Skip to content

Commit 15b30e3

Browse files
authored
Merge pull request #4211 from swiftwasm/main
[pull] swiftwasm from main
2 parents e2d2412 + 2b2dd23 commit 15b30e3

File tree

70 files changed

+3131
-1456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3131
-1456
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//===--- BinaryScan.h - C API for Swift Binary Scanning ---*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This C API is primarily intended to serve as a "static mirror" library
14+
// for querying Swift type information from binary object files.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#include "DependencyScanMacros.h"
19+
#include "CommonString.h"
20+
21+
#ifndef SWIFT_C_BINARY_SCAN_H
22+
#define SWIFT_C_BINARY_SCAN_H
23+
24+
SWIFTSCAN_BEGIN_DECLS
25+
26+
//=== Public Binary Scanner Data Types ------------------------------------===//
27+
28+
/// Container of the configuration state for binary static mirror scanning
29+
/// instance
30+
typedef void *swiftscan_static_mirror_t;
31+
32+
/// Opaque container to a conformance type info of a given protocol conformance.
33+
typedef struct swiftscan_conformance_info_s
34+
*swiftscan_static_mirror_conformance_info_t;
35+
36+
typedef struct {
37+
swiftscan_static_mirror_conformance_info_t *conformances;
38+
size_t count;
39+
} swiftscan_static_mirror_conformances_set_t;
40+
41+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
42+
swiftscan_static_mirror_conformance_info_get_type_name(
43+
swiftscan_static_mirror_conformance_info_t);
44+
45+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
46+
swiftscan_static_mirror_conformance_info_get_protocol_name(
47+
swiftscan_static_mirror_conformance_info_t);
48+
49+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
50+
swiftscan_static_mirror_conformance_info_get_mangled_type_name(
51+
swiftscan_static_mirror_conformance_info_t);
52+
53+
SWIFTSCAN_PUBLIC void
54+
swiftscan_static_mirror_conformance_info_dispose(
55+
swiftscan_static_mirror_conformance_info_t);
56+
57+
/// Create an \c swiftscan_static_mirror_t instance.
58+
/// The returned \c swiftscan_static_mirror_t is owned by the caller and must be
59+
/// disposed of using \c swiftscan_static_mirror_dispose .
60+
SWIFTSCAN_PUBLIC swiftscan_static_mirror_t
61+
swiftscan_static_mirror_create(int, const char **, const char *);
62+
63+
SWIFTSCAN_PUBLIC void
64+
swiftscan_static_mirror_dispose(swiftscan_static_mirror_t);
65+
66+
/// Identify and collect all types conforming to any of the protocol names
67+
/// specified as arguments
68+
SWIFTSCAN_PUBLIC swiftscan_static_mirror_conformances_set_t *
69+
swiftscan_static_mirror_conformances_set_create(
70+
swiftscan_static_mirror_t, int, const char **);
71+
72+
SWIFTSCAN_PUBLIC void swiftscan_static_mirror_conformances_set_dispose(
73+
swiftscan_static_mirror_conformances_set_t *);
74+
75+
SWIFTSCAN_END_DECLS
76+
77+
#endif // SWIFT_C_BINARY_SCAN_H
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===--- CommonString.h - C API for Swift Dependency Scanning ---*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_C_LIB_SWIFT_SCAN_STRING_H
14+
#define SWIFT_C_LIB_SWIFT_SCAN_STRING_H
15+
16+
#include <stdbool.h>
17+
#include <stddef.h>
18+
#include <stdint.h>
19+
20+
SWIFTSCAN_BEGIN_DECLS
21+
22+
//=== String Data Types used by LibSwift Scan ----------------------------===//
23+
24+
/**
25+
* A character string used to pass around dependency scan result metadata.
26+
* Lifetime of the string is strictly tied to the object whose field it
27+
* represents. When the owning object is released, string memory is freed.
28+
*/
29+
typedef struct {
30+
const void *data;
31+
size_t length;
32+
} swiftscan_string_ref_t;
33+
34+
typedef struct {
35+
swiftscan_string_ref_t *strings;
36+
size_t count;
37+
} swiftscan_string_set_t;
38+
39+
SWIFTSCAN_END_DECLS
40+
41+
#endif // SWIFT_C_DEPENDENCY_SCAN_H

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,15 @@
1515
//
1616
//===----------------------------------------------------------------------===//
1717

18-
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
19-
#define SWIFT_C_DEPENDENCY_SCAN_H
20-
2118
#include "DependencyScanMacros.h"
22-
#include <stdbool.h>
23-
#include <stddef.h>
24-
#include <stdint.h>
19+
#include "CommonString.h"
2520

26-
/// The version constants for the SwiftDependencyScan C API.
27-
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
28-
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
29-
#define SWIFTSCAN_VERSION_MAJOR 0
30-
#define SWIFTSCAN_VERSION_MINOR 2
21+
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
22+
#define SWIFT_C_DEPENDENCY_SCAN_H
3123

3224
SWIFTSCAN_BEGIN_DECLS
3325

34-
//=== Public Scanner Data Types -------------------------------------------===//
35-
36-
/**
37-
* A character string used to pass around dependency scan result metadata.
38-
* Lifetime of the string is strictly tied to the object whose field it
39-
* represents. When the owning object is released, string memory is freed.
40-
*/
41-
typedef struct {
42-
const void *data;
43-
size_t length;
44-
} swiftscan_string_ref_t;
45-
46-
typedef struct {
47-
swiftscan_string_ref_t *strings;
48-
size_t count;
49-
} swiftscan_string_set_t;
26+
//=== Public Dependency Scanner Data Types -------------------------------===//
5027

5128
typedef enum {
5229
// This dependency info encodes two ModuleDependencyKind types:
@@ -368,6 +345,8 @@ swiftscan_scanner_cache_load(swiftscan_scanner_t scanner,
368345
SWIFTSCAN_PUBLIC void
369346
swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
370347

348+
//=== Experimental compiler invocation operations -------------------------===//
349+
371350
/// An entry point to invoke the compiler via a library call.
372351
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);
373352

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===--- LibSwiftScan.h - C API for Swift Dependency Scanning ---*- C ---*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This C API is primarily intended to serve as:
14+
// - Swift Driver's dependency scanning facility
15+
// (https://github.com/apple/swift-driver).
16+
// - An object-file scanning facility for extracting of Swift type information
17+
//
18+
//===----------------------------------------------------------------------===//
19+
20+
#ifndef SWIFT_C_SWIFT_SCAN_H
21+
#define SWIFT_C_SWIFT_SCAN_H
22+
23+
/// The version constants for the SwiftDependencyScan C API.
24+
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
25+
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
26+
#define SWIFTSCAN_VERSION_MAJOR 0
27+
#define SWIFTSCAN_VERSION_MINOR 3
28+
29+
#include "DependencyScan.h"
30+
#include "BinaryScan.h"
31+
32+
#endif // SWIFT_C_SWIFT_SCAN_H
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module _InternalSwiftScan {
2-
header "DependencyScan.h"
2+
header "LibSwiftScan.h"
33
link "_InternalSwiftScan"
44
}

include/swift/ABI/TaskStatus.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,21 @@ class ChildTaskStatusRecord : public TaskStatusRecord {
164164
/// and are only tracked by their respective `TaskGroupTaskStatusRecord`.
165165
class TaskGroupTaskStatusRecord : public TaskStatusRecord {
166166
AsyncTask *FirstChild;
167+
AsyncTask *LastChild;
167168

168169
public:
169170
TaskGroupTaskStatusRecord()
170-
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup), FirstChild(nullptr) {
171+
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup),
172+
FirstChild(nullptr),
173+
LastChild(nullptr) {
171174
}
172175

173176
TaskGroupTaskStatusRecord(AsyncTask *child)
174-
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup), FirstChild(child) {}
177+
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup),
178+
FirstChild(child),
179+
LastChild(child) {
180+
assert(!LastChild || !LastChild->childFragment()->getNextChild());
181+
}
175182

176183
TaskGroup *getGroup() { return reinterpret_cast<TaskGroup *>(this); }
177184

@@ -185,38 +192,28 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
185192
assert(child->hasGroupChildFragment());
186193
assert(child->groupChildFragment()->getGroup() == getGroup());
187194

195+
auto oldLastChild = LastChild;
196+
LastChild = child;
197+
188198
if (!FirstChild) {
189199
// This is the first child we ever attach, so store it as FirstChild.
190200
FirstChild = child;
191201
return;
192202
}
193203

194-
// We need to traverse the siblings to find the last one and add the child
195-
// there.
196-
// FIXME: just set prepend to the current head, no need to traverse.
197-
198-
auto cur = FirstChild;
199-
while (cur) {
200-
// no need to check hasChildFragment, all tasks we store here have them.
201-
auto fragment = cur->childFragment();
202-
if (auto next = fragment->getNextChild()) {
203-
cur = next;
204-
} else {
205-
// we're done searching and `cur` is the last
206-
break;
207-
}
208-
}
209-
210-
cur->childFragment()->setNextChild(child);
204+
oldLastChild->childFragment()->setNextChild(child);
211205
}
212206

213207
void detachChild(AsyncTask *child) {
214208
assert(child && "cannot remove a null child from group");
215209
if (FirstChild == child) {
216210
FirstChild = getNextChildTask(child);
211+
if (FirstChild == nullptr) {
212+
LastChild = nullptr;
213+
}
217214
return;
218215
}
219-
216+
220217
AsyncTask *prev = FirstChild;
221218
// Remove the child from the linked list, i.e.:
222219
// prev -> afterPrev -> afterChild
@@ -230,6 +227,9 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
230227
if (afterPrev == child) {
231228
auto afterChild = getNextChildTask(child);
232229
prev->childFragment()->setNextChild(afterChild);
230+
if (child == LastChild) {
231+
LastChild = prev;
232+
}
233233
return;
234234
}
235235

include/swift/AST/ActorIsolation.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class raw_ostream;
2626
namespace swift {
2727
class DeclContext;
2828
class ModuleDecl;
29+
class VarDecl;
2930
class NominalTypeDecl;
3031
class SubstitutionMap;
32+
class AbstractFunctionDecl;
3133

3234
/// Determine whether the given types are (canonically) equal, declared here
3335
/// to avoid having to include Types.h.
@@ -36,6 +38,11 @@ bool areTypesEqual(Type type1, Type type2);
3638
/// Determine whether the given type is suitable as a concurrent value type.
3739
bool isSendableType(ModuleDecl *module, Type type);
3840

41+
/// Determines if the 'let' can be read from anywhere within the given module,
42+
/// regardless of the isolation or async-ness of the context in which
43+
/// the var is read.
44+
bool isLetAccessibleAnywhere(const ModuleDecl *fromModule, VarDecl *let);
45+
3946
/// Describes the actor isolation of a given declaration, which determines
4047
/// the actors with which it can interact.
4148
class ActorIsolation {
@@ -169,6 +176,9 @@ ActorIsolation getActorIsolation(ValueDecl *value);
169176
/// Determine how the given declaration context is isolated.
170177
ActorIsolation getActorIsolationOfContext(DeclContext *dc);
171178

179+
/// Determines whether this function's body uses flow-sensitive isolation.
180+
bool usesFlowSensitiveIsolation(AbstractFunctionDecl const *fn);
181+
172182
void simple_display(llvm::raw_ostream &out, const ActorIsolation &state);
173183

174184
} // end namespace swift

include/swift/AST/DiagnosticsSIL.def

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,6 @@ ERROR(variable_defer_use_uninit,none,
168168
ERROR(self_closure_use_uninit,none,
169169
"'self' captured by a closure before all members were initialized", ())
170170

171-
ERROR(self_disallowed_nonisolated_actor_init,none,
172-
"%select{|this use of }0actor 'self' cannot %2 %select{from|in}0 "
173-
"%select{a non-isolated, designated|a global-actor isolated}1 initializer",
174-
(bool, bool, StringRef))
175-
ERROR(self_disallowed_plain_actor_init,none,
176-
"%select{|this use of }0actor 'self' can only %1 %select{from|in}0 an async initializer",
177-
(bool, StringRef))
178-
NOTE(actor_convenience_init,none,
179-
"convenience initializers allow non-isolated use of 'self' once "
180-
"initialized",
181-
())
182-
183-
184171

185172

186173
ERROR(variable_addrtaken_before_initialized,none,
@@ -625,6 +612,16 @@ WARNING(warning_int_to_fp_inexact, none,
625612
"'%1' is not exactly representable as %0; it becomes '%2'",
626613
(Type, StringRef, StringRef))
627614

615+
// Flow-isolation diagnostics
616+
ERROR(isolated_after_nonisolated, none,
617+
"cannot access %1 %2 here in %select{non-isolated initializer|deinitializer}0",
618+
(bool, DescriptiveDeclKind, DeclName))
619+
NOTE(nonisolated_blame, none, "after %1%2 %3, "
620+
"only non-isolated properties of 'self' can be accessed from "
621+
"%select{this init|a deinit}0", (bool, StringRef, StringRef, DeclName))
622+
ERROR(non_sendable_from_deinit,none,
623+
"cannot access %1 %2 with a non-sendable type %0 from non-isolated deinit",
624+
(Type, DescriptiveDeclKind, DeclName))
628625

629626
// Yield usage errors
630627
ERROR(return_before_yield, none, "accessor must yield before returning",())

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,8 @@ ERROR(extension_metatype,none,
19041904
ERROR(extension_specialization,none,
19051905
"constrained extension must be declared on the unspecialized generic "
19061906
"type %0 with constraints specified by a 'where' clause", (Identifier))
1907+
ERROR(extension_placeholder,none,
1908+
"cannot extend a type that contains placeholders", ())
19071909
ERROR(extension_stored_property,none,
19081910
"extensions must not contain stored properties", ())
19091911
NOTE(extension_stored_property_fixit,none,
@@ -4708,9 +4710,6 @@ ERROR(nonisolated_local_var,none,
47084710
ERROR(nonisolated_actor_sync_init,none,
47094711
"'nonisolated' on an actor's synchronous initializer is invalid",
47104712
())
4711-
ERROR(nonisolated_actor_convenience_init,none,
4712-
"'nonisolated' on an actor's convenience initializer is redundant",
4713-
())
47144713

47154714
ERROR(actor_instance_property_wrapper,none,
47164715
"%0 property in property wrapper type %1 cannot be isolated to "

0 commit comments

Comments
 (0)