Skip to content

Commit 103861b

Browse files
authored
Merge branch 'master' into uniterator
2 parents 7594335 + aa3e16d commit 103861b

File tree

125 files changed

+3058
-659
lines changed

Some content is hidden

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

125 files changed

+3058
-659
lines changed

include/swift/AST/Attr.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(optional, Optional,
133133
OnConstructor | OnFunc | OnAccessor | OnVar | OnSubscript |
134134
DeclModifier,
135135
5)
136-
// NOTE: 6 is unused
136+
SIMPLE_DECL_ATTR(dynamicCallable, DynamicCallable,
137+
OnNominalType,
138+
6)
137139
SIMPLE_DECL_ATTR(noreturn, NoReturn,
138140
OnFunc | OnAccessor,
139141
7)
@@ -384,6 +386,10 @@ DECL_ATTR(_dynamicReplacement, DynamicReplacement,
384386
SIMPLE_DECL_ATTR(_borrowed, Borrowed,
385387
OnVar | OnSubscript | UserInaccessible |
386388
NotSerialized, 81)
389+
DECL_ATTR(_private, PrivateImport,
390+
OnImport |
391+
UserInaccessible |
392+
NotSerialized, 82)
387393

388394
#undef TYPE_ATTR
389395
#undef DECL_ATTR_ALIAS

include/swift/AST/Attr.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,26 @@ class ObjCAttr final : public DeclAttribute,
901901
}
902902
};
903903

904+
class PrivateImportAttr final
905+
: public DeclAttribute {
906+
StringRef SourceFile;
907+
908+
PrivateImportAttr(SourceLoc atLoc, SourceRange baseRange,
909+
StringRef sourceFile, SourceRange parentRange);
910+
911+
public:
912+
static PrivateImportAttr *create(ASTContext &Ctxt, SourceLoc AtLoc,
913+
SourceLoc PrivateLoc, SourceLoc LParenLoc,
914+
StringRef sourceFile, SourceLoc RParenLoc);
915+
916+
StringRef getSourceFile() const {
917+
return SourceFile;
918+
}
919+
static bool classof(const DeclAttribute *DA) {
920+
return DA->getKind() == DAK_PrivateImport;
921+
}
922+
};
923+
904924
/// The @_dynamicReplacement(for:) attribute.
905925
class DynamicReplacementAttr final
906926
: public DeclAttribute,

include/swift/AST/Builtins.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ BUILTIN_MISC_OPERATION(Swift3ImplicitObjCEntrypoint, "swift3ImplicitObjCEntrypoi
536536
/// willThrow: Error -> ()
537537
BUILTIN_MISC_OPERATION(WillThrow, "willThrow", "", Special)
538538

539+
/// poundAssert has type (Builtin.Int1, Builtin.RawPointer) -> ().
540+
BUILTIN_MISC_OPERATION(PoundAssert, "poundAssert", "", Special)
541+
539542
#undef BUILTIN_MISC_OPERATION
540543

541544
/// Builtins for instrumentation added by sanitizers during SILGen.

include/swift/AST/Decl.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class alignas(1 << DeclAlignInBits) Decl {
573573
HasAnyUnavailableValues : 1
574574
);
575575

576-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1,
576+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1,
577577
/// If the module was or is being compiled with `-enable-testing`.
578578
TestingEnabled : 1,
579579

@@ -586,7 +586,10 @@ class alignas(1 << DeclAlignInBits) Decl {
586586
RawResilienceStrategy : 1,
587587

588588
/// Whether all imports have been resolved. Used to detect circular imports.
589-
HasResolvedImports : 1
589+
HasResolvedImports : 1,
590+
591+
// If the module was or is being compiled with `-enable-private-imports`.
592+
PrivateImportsEnabled : 1
590593
);
591594

592595
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,
@@ -3019,6 +3022,14 @@ static inline bool isRawPointerKind(PointerTypeKind PTK) {
30193022
llvm_unreachable("Unhandled PointerTypeKind in switch.");
30203023
}
30213024

3025+
enum KeyPathTypeKind : unsigned char {
3026+
KPTK_AnyKeyPath,
3027+
KPTK_PartialKeyPath,
3028+
KPTK_KeyPath,
3029+
KPTK_WritableKeyPath,
3030+
KPTK_ReferenceWritableKeyPath
3031+
};
3032+
30223033
/// NominalTypeDecl - a declaration of a nominal type, like a struct.
30233034
class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
30243035
SourceRange Braces;
@@ -3240,6 +3251,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
32403251
/// Is this the decl for Optional<T>?
32413252
bool isOptionalDecl() const;
32423253

3254+
/// Is this a key path type?
3255+
Optional<KeyPathTypeKind> getKeyPathTypeKind() const;
3256+
32433257
private:
32443258
/// Predicate used to filter StoredPropertyRange.
32453259
struct ToStoredProperty {

include/swift/AST/DiagnosticsParse.def

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ WARNING(escaped_parameter_name,none,
9999
"keyword '%0' does not need to be escaped in argument list",
100100
(StringRef))
101101

102+
ERROR(forbidden_interpolated_string,none,
103+
"%0 cannot be an interpolated string literal", (StringRef))
104+
ERROR(forbidden_extended_escaping_string,none,
105+
"%0 cannot be an extended escaping string literal", (StringRef))
106+
102107
//------------------------------------------------------------------------------
103108
// MARK: Lexer diagnostics
104109
//------------------------------------------------------------------------------
@@ -1263,6 +1268,17 @@ ERROR(expr_typeof_expected_rparen,PointsToFirstBadToken,
12631268
ERROR(expr_dynamictype_deprecated,PointsToFirstBadToken,
12641269
"'.dynamicType' is deprecated. Use 'type(of: ...)' instead", ())
12651270

1271+
ERROR(pound_assert_disabled,PointsToFirstBadToken,
1272+
"#assert is an experimental feature that is currently disabled", ())
1273+
ERROR(pound_assert_expected_lparen,PointsToFirstBadToken,
1274+
"expected '(' in #assert directive", ())
1275+
ERROR(pound_assert_expected_rparen,PointsToFirstBadToken,
1276+
"expected ')' in #assert directive", ())
1277+
ERROR(pound_assert_expected_expression,PointsToFirstBadToken,
1278+
"expected a condition expression", ())
1279+
ERROR(pound_assert_expected_string_literal,PointsToFirstBadToken,
1280+
"expected a string literal", ())
1281+
12661282
//------------------------------------------------------------------------------
12671283
// MARK: Attribute-parsing diagnostics
12681284
//------------------------------------------------------------------------------
@@ -1311,11 +1327,6 @@ ERROR(alignment_must_be_positive_integer,none,
13111327
ERROR(swift_native_objc_runtime_base_must_be_identifier,none,
13121328
"@_swift_native_objc_runtime_base class name must be an identifier", ())
13131329

1314-
ERROR(attr_interpolated_string,none,
1315-
"'%0' cannot be an interpolated string literal", (StringRef))
1316-
ERROR(attr_extended_escaping_string,none,
1317-
"'%0' cannot be an extended escaping string literal", (StringRef))
1318-
13191330
ERROR(attr_only_at_non_local_scope, none,
13201331
"attribute '%0' can only be used in a non-local scope", (StringRef))
13211332

@@ -1417,6 +1428,15 @@ ERROR(attr_dynamic_replacement_expected_for,none,
14171428
ERROR(attr_dynamic_replacement_expected_colon,none,
14181429
"expected ':' after @_dynamicReplacement(for", ())
14191430

1431+
ERROR(attr_private_import_expected_rparen,none,
1432+
"expected ')' after function name for @_private", ())
1433+
ERROR(attr_private_import_expected_sourcefile, none,
1434+
"expected 'sourceFile' in '_private' attribute", ())
1435+
ERROR(attr_private_import_expected_sourcefile_name,none,
1436+
"expected a source file name in @_private(sourceFile:)", ())
1437+
ERROR(attr_private_import_expected_colon,none,
1438+
"expected ':' after @_private(sourceFile", ())
1439+
14201440
// opened
14211441
ERROR(opened_attribute_expected_lparen,none,
14221442
"expected '(' after 'opened' attribute", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ ERROR(ambiguous_decl_in_module,none,
759759
ERROR(module_not_testable,none,
760760
"module %0 was not compiled for testing", (Identifier))
761761

762+
ERROR(module_not_compiled_for_private_import,none,
763+
"module %0 was not compiled for private import", (Identifier))
764+
765+
762766
// Operator decls
763767
ERROR(ambiguous_operator_decls,none,
764768
"ambiguous operator declarations found for operator", ())
@@ -1042,6 +1046,14 @@ NOTE(archetype_declared_in_type,none,
10421046
NOTE(unbound_generic_parameter_explicit_fix,none,
10431047
"explicitly specify the generic arguments to fix this issue", ())
10441048

1049+
ERROR(invalid_dynamic_callable_type,none,
1050+
"@dynamicCallable attribute requires %0 to have either a valid "
1051+
"'dynamicallyCall(withArguments:)' method or "
1052+
"'dynamicallyCall(withKeywordArguments:)' method", (Type))
1053+
ERROR(missing_dynamic_callable_kwargs_method,none,
1054+
"@dynamicCallable type %0 cannot be applied with keyword arguments; "
1055+
"missing 'dynamicCall(withKeywordArguments:)' method", (Type))
1056+
10451057
ERROR(type_invalid_dml,none,
10461058
"@dynamicMemberLookup attribute requires %0 to have a "
10471059
"'subscript(dynamicMember:)' member with a string index", (Type))
@@ -3926,6 +3938,8 @@ NOTE(dynamic_replacement_found_function_of_type, none,
39263938
"found function %0 of type %1", (DeclName, Type))
39273939
ERROR(dynamic_replacement_not_in_extension, none,
39283940
"dynamicReplacement(for:) of %0 is not defined in an extension or at the file level", (DeclName))
3941+
ERROR(dynamic_replacement_must_not_be_dynamic, none,
3942+
"dynamicReplacement(for:) of %0 must not be dynamic itself", (DeclName))
39293943

39303944
//------------------------------------------------------------------------------
39313945
// MARK: @available

include/swift/AST/KnownIdentifiers.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ IDENTIFIER(decode)
4747
IDENTIFIER(decodeIfPresent)
4848
IDENTIFIER(Decoder)
4949
IDENTIFIER(decoder)
50+
IDENTIFIER(dynamicallyCall)
5051
IDENTIFIER(dynamicMember)
5152
IDENTIFIER(Element)
5253
IDENTIFIER(Encodable)
@@ -114,6 +115,8 @@ IDENTIFIER(Value)
114115
IDENTIFIER(value)
115116
IDENTIFIER_WITH_NAME(value_, "_value")
116117
IDENTIFIER(with)
118+
IDENTIFIER(withArguments)
119+
IDENTIFIER(withKeywordArguments)
117120

118121
// Kinds of layout constraints
119122
IDENTIFIER_WITH_NAME(UnknownLayout, "_UnknownLayout")

include/swift/AST/Module.h

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ class ModuleDecl : public DeclContext, public TypeDecl {
283283
Bits.ModuleDecl.TestingEnabled = enabled;
284284
}
285285

286+
/// Returns true if this module was or is begin compile with
287+
/// `-enable-private-imports`.
288+
bool arePrivateImportsEnabled() const {
289+
return Bits.ModuleDecl.PrivateImportsEnabled;
290+
}
291+
void setPrivateImportsEnabled(bool enabled = true) {
292+
Bits.ModuleDecl.PrivateImportsEnabled = true;
293+
}
294+
286295
/// Returns true if there was an error trying to load this module.
287296
bool failedToLoad() const {
288297
return Bits.ModuleDecl.FailedToLoad;
@@ -844,20 +853,38 @@ class SourceFile final : public FileUnit {
844853

845854
/// This source file has access to testable declarations in the imported
846855
/// module.
847-
Testable = 0x2
856+
Testable = 0x2,
857+
858+
/// This source file has access to private declarations in the imported
859+
/// module.
860+
PrivateImport = 0x4,
848861
};
849862

850863
/// \see ImportFlags
851864
using ImportOptions = OptionSet<ImportFlags>;
852865

866+
typedef std::pair<ImportOptions, StringRef> ImportOptionsAndFilename;
867+
868+
struct ImportedModuleDesc {
869+
ModuleDecl::ImportedModule module;
870+
ImportOptions importOptions;
871+
StringRef filename;
872+
873+
ImportedModuleDesc(ModuleDecl::ImportedModule module, ImportOptions options)
874+
: module(module), importOptions(options) {}
875+
ImportedModuleDesc(ModuleDecl::ImportedModule module, ImportOptions options,
876+
StringRef filename)
877+
: module(module), importOptions(options), filename(filename) {}
878+
};
879+
853880
private:
854881
std::unique_ptr<LookupCache> Cache;
855882
LookupCache &getCache() const;
856883

857884
/// This is the list of modules that are imported by this module.
858885
///
859886
/// This is filled in by the Name Binding phase.
860-
ArrayRef<std::pair<ModuleDecl::ImportedModule, ImportOptions>> Imports;
887+
ArrayRef<ImportedModuleDesc> Imports;
861888

862889
/// A unique identifier representing this file; used to mark private decls
863890
/// within the file to keep them from conflicting with other files in the
@@ -961,10 +988,9 @@ class SourceFile final : public FileUnit {
961988
ImplicitModuleImportKind ModImpKind, bool KeepParsedTokens = false,
962989
bool KeepSyntaxTree = false);
963990

964-
void
965-
addImports(ArrayRef<std::pair<ModuleDecl::ImportedModule, ImportOptions>> IM);
991+
void addImports(ArrayRef<ImportedModuleDesc> IM);
966992

967-
bool hasTestableImport(const ModuleDecl *module) const;
993+
bool hasTestableOrPrivateImport(AccessLevel accessLevel, const ValueDecl *ofDecl) const;
968994

969995
void clearLookupCache();
970996

@@ -1224,12 +1250,29 @@ class LoadedFile : public FileUnit {
12241250
assert(classof(this) && "invalid kind");
12251251
}
12261252

1253+
/// A map from private/fileprivate decls to the file they were defined in.
1254+
llvm::DenseMap<const ValueDecl *, Identifier> FilenameForPrivateDecls;
1255+
12271256
public:
1257+
12281258
/// Returns an arbitrary string representing the storage backing this file.
12291259
///
12301260
/// This is usually a filesystem path.
12311261
virtual StringRef getFilename() const;
12321262

1263+
void addFilenameForPrivateDecl(const ValueDecl *decl, Identifier id) {
1264+
assert(!FilenameForPrivateDecls.count(decl) ||
1265+
FilenameForPrivateDecls[decl] == id);
1266+
FilenameForPrivateDecls[decl] = id;
1267+
}
1268+
1269+
StringRef getFilenameForPrivateDecl(const ValueDecl *decl) {
1270+
auto it = FilenameForPrivateDecls.find(decl);
1271+
if (it == FilenameForPrivateDecls.end())
1272+
return StringRef();
1273+
return it->second.str();
1274+
}
1275+
12331276
/// Look up an operator declaration.
12341277
///
12351278
/// \param name The operator name ("+", ">>", etc.)

include/swift/AST/Stmt.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,31 @@ class ThrowStmt : public Stmt {
12251225
}
12261226
};
12271227

1228+
/// PoundAssertStmt - Asserts that a condition is true, at compile time.
1229+
class PoundAssertStmt : public Stmt {
1230+
SourceRange Range;
1231+
Expr *Condition;
1232+
StringRef Message;
1233+
1234+
public:
1235+
PoundAssertStmt(SourceRange Range, Expr *condition, StringRef message)
1236+
: Stmt(StmtKind::PoundAssert, /*Implicit=*/false),
1237+
Range(Range),
1238+
Condition(condition),
1239+
Message(message) {}
1240+
1241+
SourceRange getSourceRange() const { return Range; }
1242+
1243+
Expr *getCondition() const { return Condition; }
1244+
StringRef getMessage() const { return Message; }
1245+
1246+
void setCondition(Expr *condition) { Condition = condition; }
1247+
1248+
static bool classof(const Stmt *S) {
1249+
return S->getKind() == StmtKind::PoundAssert;
1250+
}
1251+
};
1252+
12281253
} // end namespace swift
12291254

12301255
#endif // SWIFT_AST_STMT_H

include/swift/AST/StmtNodes.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ STMT(Continue, Stmt)
6767
STMT(Fallthrough, Stmt)
6868
STMT(Fail, Stmt)
6969
STMT(Throw, Stmt)
70-
LAST_STMT(Throw)
70+
STMT(PoundAssert, Stmt)
71+
LAST_STMT(PoundAssert)
7172

7273
#undef STMT_RANGE
7374
#undef LABELED_STMT

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ namespace swift {
211211
/// optimized custom allocator, so that memory debugging tools can be used.
212212
bool UseMalloc = false;
213213

214+
/// \brief Enable experimental #assert feature.
215+
bool EnableExperimentalStaticAssert = false;
216+
214217
/// \brief Enable experimental property behavior feature.
215218
bool EnableExperimentalPropertyBehaviors = false;
216219

include/swift/Frontend/FrontendOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ class FrontendOptions {
192192
/// \see ModuleDecl::isTestingEnabled
193193
bool EnableTesting = false;
194194

195+
/// Indicates whether we are compiling for private imports.
196+
///
197+
/// \see ModuleDecl::arePrivateImportsEnabled
198+
bool EnablePrivateImports = false;
199+
195200
/// Enables the "fully resilient" resilience strategy.
196201
///
197202
/// \see ResilienceStrategy::Resilient

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ def enable_sil_opaque_values : Flag<["-"], "enable-sil-opaque-values">,
319319
def enable_large_loadable_types : Flag<["-"], "enable-large-loadable-types">,
320320
HelpText<"Enable Large Loadable types IRGen pass">;
321321

322+
def enable_experimental_static_assert :
323+
Flag<["-"], "enable-experimental-static-assert">,
324+
HelpText<"Enable experimental #assert">;
325+
322326
def enable_experimental_property_behaviors :
323327
Flag<["-"], "enable-experimental-property-behaviors">,
324328
HelpText<"Enable experimental property behaviors">;

0 commit comments

Comments
 (0)