Commit Graph

48 Commits

Author SHA1 Message Date
Robert Widmann
f27916b76c Inline TypeChecker::diagnoseInlinableLocalType 2019-11-05 22:52:28 -08:00
Robert Widmann
56b6e53dae Remove raw references to PatternBindingEntry APIs
Switch most callers to explicit indices.  The exceptions lie in things that needs to manipulate the parsed output directly including the Parser and components of the ASTScope.  These are included as friend class exceptions.
2019-10-17 13:31:14 -07:00
Slava Pestov
d2c579d5f7 Sema: Move some checks from validateType() down to resolveType()
validateType() is just the TypeLoc-based wrapper; it should not do
any checks that resolveType() itself does not do.
2019-10-10 13:53:40 -04:00
Slava Pestov
bbce38409c Sema: Decouple availability checking from the TypeChecker 2019-09-24 22:51:23 -04:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Robert Widmann
30f4df3b00 Make validateType a utility method
Move around some code so that TypeChecker::validateType is now a utility
method of the type checker.  This cleans up at least one request that no
longer needs to grab the type checker from the AST context.
2019-09-13 15:16:14 -07:00
Slava Pestov
bdaeaf1e5f Don't pass SubstitutionMap by const reference 2019-07-24 12:43:36 -04:00
Jordan Rose
3b4bb1960d @_implementationOnly: fix over-eager checking for vars in extensions (#24629)
The logic I had here checked whether an extension used an
implementation-only type whenever there was a declaration within that
extension that needed checking...but unfortunately that included not
just PatternBindingDecls (whose access is filtered at a later step)
but things like IfConfigDecls (#if). Change this to only check
signatures of extensions with ABI-public members, something that is
tested once when visiting an ExtensionDecl.

Additionally, skip AccessorDecls entirely, since they'll be tested
as part of the corresponding subscript or var. This saves a duplicate
diagnostic.

rdar://problem/50541589
2019-05-16 13:13:48 -07:00
Jordan Rose
778f0f82f4 Separate TypeDeclFinder from AccessScopeChecker (#23957)
...and move the latter into lib/Sema as TypeAccessScopeChecker, since
it's not interesting outside of Sema anyway.

No functionality change.
2019-04-18 20:14:21 -07:00
Jordan Rose
326fa14f8b Don't bother checking implementation-only import use for accessors
Their associated AbstractStorageDecl is already being checked, and
will produce a better error.
2019-04-11 16:33:23 -07:00
Jordan Rose
a4606111af Adjust the implementation-only diagnostics to sound more similar
John and I had slightly different styles when adding these; better
to keep them in harmony.
2019-04-11 16:33:23 -07:00
Jordan Rose
7006aa0b9f Check for use of implementation-only conformances in inlinable code
This includes both the types and the values (generic functions, etc)
used in the inlinable code. We get some effectively duplicate
diagnostics at this point because of this, but we can deal with that
at a future date.

Last part of rdar://problem/48991061
2019-04-10 11:09:07 -07:00
Jordan Rose
590551781a Pass a ConcreteDeclRef through for availability checking where present
This will be used in the next commit for checking conformance use in
inlinable function bodies, but for now it's No Functionality Change.
2019-04-10 11:09:07 -07:00
Jordan Rose
a15dec8774 Diagnose typealiases of non-public types in inlinable functions (#23912)
...as a warning, since we didn't check this correctly in Swift 5.
For parseable interfaces, these typealiases won't work at all.
2019-04-10 09:21:44 -07:00
John McCall
ae6561c32c Checks for implementation-only imports in @inlinable code.
Part of rdar://48991061
2019-04-05 16:30:25 -04:00
Slava Pestov
a2049972ca AST: Add ModuleDecl::isResilient()
This cleans up some code. I'm keeping the ResilienceStrategy enum around
though, in case we want to use it to version the ABI in the future.
2019-03-26 18:42:59 -04:00
Slava Pestov
bd6490b391 SIL: Introduce '@_alwaysEmitIntoClient' attribute for use by standard library
This is like '@inlinable', except that the symbol does not have a public
entry point in the generated binary at all; it is deserialized and a copy
is always emitted into the client binary, with shared linkage.

Just like '@inlinable', if you apply this to an internal declaration it
becomes '@usableFromInline' automatically.

This uses the same mechanism as default arguments ever since Swift 4, so
it should work reasonably well, but there are rough edges with diagnostics
and such. Don't use this if you are not the standard library.

Fixes <rdar://problem/33767512>, <https://bugs.swift.org/browse/SR-5646>.
2019-02-18 17:10:57 -05:00
Harlan Haskins
1abeeb8b92 [Sema] Diagnose internal(set) from @inlinable functions
This patch mainly consolidates the functions used to check accessors vs.
other decls, and makes sure we check setter access as well as regular
decl access.

rdar://45217648
2018-12-07 12:46:19 -08:00
Slava Pestov
3e864b26aa AST: @inline(__always) no longer implies @inlinable
Fixes <rdar://problem/44657000>.
2018-11-12 21:00:15 -05:00
Arnold Schwaighofer
c158106329 Allow dynamic without @objc in -swift-version 5
Dynamic functions will allow replacement of their implementation at
runtime.
2018-11-06 09:53:21 -08:00
Harlan Haskins
5f9ff021d4 [Sema] Allow non-public static property initializers in @_fixed_layout types
Static properties are not subject to the same restrictions as properties
whose initializers are exposed to clients in @_fixed_layout types.

rdar://45080912
2018-10-08 18:02:30 -07:00
Jordan Rose
df1ef05c4c Remove unwanted exceptions from @inlinable checking
- Treat protocol requirements just like associated types in how they
  inherit usable-from-inline-ness, rather than special-casing them in
  the check for inlinable code.

- Enum elements are already treated this way, so we can remove a
  redundant check for that.

- Finally, start enforcing that 'dynamic' declarations need to be
  '@usableFromInline' to be used in inlinable functions...in Swift 5
  mode or resilient code. I didn't even add a warning in Swift 4/4.2
  because it was illegal to use '@usableFromInline' on a 'dynamic'
  declaration in Swift 4.2. (Oops.)
2018-10-05 12:21:01 -07:00
Slava Pestov
2b75d7f1b0 Sema: Don't complain about internal type aliases referenced from @inlinable functions in Swift < 4.2 2018-06-25 17:00:47 -07:00
Slava Pestov
b137b08822 Sema: Type aliases referenced from @inlinable functions must be public or @usableFromInline
This is a source breaking change, so emit a warning in Swift 4 mode,
and an error in Swift 5 mode.
2018-06-15 14:16:05 -07:00
Slava Pestov
96901f1983 SE-0193: Public default argument generators cannot reference declarations that are @usableFromInline 2018-04-05 16:56:34 -07:00
Slava Pestov
4af8ff6872 Sema: TypeChecker::getFragileFunctionKind() returns if @usableFromInline references are allowed
For now, always true, soon, default arguments of public functions
will return false here.
2018-04-05 16:47:26 -07:00
Slava Pestov
b280f61f83 Sema: Resilience diagnostics pre-compute a few things 2018-04-05 16:42:45 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Slava Pestov
a293790e7d Fix a few unused variable warnings 2018-01-14 21:39:53 -08:00
John McCall
52bb547a7e Merge pull request #13866 from rjmccall/accessor-decl
Split AccessorDecl out from FuncDecl.  NFC.
2018-01-12 17:02:35 -05:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Slava Pestov
6ac2dde97e Sema: Enforce inlinable restrictions for stored property initializers in fixed layout types
We want stored property initializers of fixed layout structs to be
inlinable, so that inlinable initializers can be fully eliminated
by the optimizer.

This is the first step in fixing <rdar://problem/36454839>.
2018-01-12 00:06:03 -08:00
Jordan Rose
ec5ba41108 Simplify diagnoseResilientConstructor all the way away.
Now that struct initializers "just" fall into the delegating case when
they're made inlinable, the only interesting case is class
initializers, which can be checked in a more direct way than what we
were doing before.
2017-11-10 16:09:06 -08:00
Jordan Rose
14198a360c Treat cross-module struct initializers as delegating in Swift 5
(and when the struct in question is non-fixed-layout, which was
already implemented)

This ensures that these initializers are never fieldwise in Swift 5
mode, which makes it safe for library authors to add new fields.
2017-11-10 10:59:24 -08:00
Slava Pestov
82999d8177 Sema: Don't allow @_inlinable or @_versioned to be applied to dynamic declarations 2017-10-31 13:37:20 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Slava Pestov
9b2b3b5969 Sema: Don't talk about @_versioned in diagnostics for default arguments
Fixes <rdar://problem/32445206> and
<https://bugs.swift.org/browse/SR-4648>.
2017-06-16 17:00:15 -07:00
Slava Pestov
89dc5afa57 Sema: Targeted fix for bad interaction between resilience checks and -enable-testing
The -enable-testing flag makes ValueDecl::getEffectiveAccess()
say that internal declarations are public.

This would lead us to emit spurious diagnostics if a default
argument of an internal function referenced a private symbol,
for example, which is something we actually want to allow.

This is a second revision of the patch -- instead of changing
getEffectiveAccess() to take an extra parameter, this changes
getFormalAccessScope() instead.

Fixes <rdar://problem/32592973>.
2017-06-08 01:35:44 -07:00
Slava Pestov
7cfa34952a Revert "Sema: Targeted fix for bad interaction between resilience checks and -enable-testing"
This reverts commit 66173a9b97.
2017-06-07 22:06:54 -07:00
Slava Pestov
66173a9b97 Sema: Targeted fix for bad interaction between resilience checks and -enable-testing
The -enable-testing flag makes ValueDecl::getEffectiveAccess()
say that internal declarations are public.

This would lead us to emit spurious diagnostics if a default
argument of an internal function referenced a private symbol,
for example, which is something we actually want to allow.

Hack around this by adding a new 'forLinkage' parameter to
getEffectiveAccess(). When this is false, we ignore the
-enable-testing flag, and only look for the @_versioned
attribute.

I'm not very happy with the fix, because it only compliates
the subtle behaviors of getFormalAccess(), getEffectiveAccess()
and getFormalAccessScope() further. But refactoring this is
a bigger change than I'm willing to put into swift-4.0-branch.

Fixes <rdar://problem/32592973>.
2017-06-07 21:43:37 -07:00
Slava Pestov
0bc802e7ad SourceKit: Fix indexing crash with protocol typealiases
The root cause is that NormalProtocolConformance::forEachValueWitness()
needs to skip protocol members that are not requirements.

Otherwise we end up passing such a non-requirement member down to
NormalProtocolConformance::getWitness() and hit an assert when we
cannot find it.

It looks like this code path was only ever hit from SourceKit.
The fix moves TypeChecker::isRequirement() to a method on ValueDecl,
and calls it in the right places.

Fixes <https://bugs.swift.org/browse/SR-3815>.
2017-02-20 03:35:19 -08:00
Slava Pestov
fd40597d90 Sema: Extend prohibition of @_inlineable designated initializers to classes
This check only applied to struct and enum initializers previously,
but that was an oversight.
2017-02-14 15:48:26 -08:00
Slava Pestov
f0ecd1c1a3 Sema: Lift unnecessary restriction on initializers defined in extensions of resilient protocols
The restriction only applies to initializers in extensions of
concrete types; protocol extension initializers are OK.

Fixes <rdar://problem/30351393>.
2017-02-13 00:24:13 -08:00
Slava Pestov
b83bb7d614 Sema: Fix bug where enum cases could not be referenced from inlineable context
Enum cases do not have their own accessibility or @_versioned
attribute, and we already diagnose invalid references to the
enum type itself.
2017-01-29 22:34:47 -08:00
Slava Pestov
0c294314d0 Sema: Diagnose invalid initializers on resilient types
Value type initializers must initialize stored properties directly
if they do not delegate to another initializer via self.init().

Since direct stored property access is not permitted for resilient
value types from outside their resilience domain, this means that
such initializers are prohibited in two cases:

- If the initializer is defined in an extension from outside the
  value type's resilience domain

- If the initializer is public and @_inlineable, since it might get
  inlined outside the value type's resilience domain

Right now, such initializers cannot *assign* to self either;
I filed <https://bugs.swift.org/browse/SR-3686> to track the issue.
2017-01-20 01:22:51 -08:00
Slava Pestov
ec028235be Sema: Fix incorrect diagnostic when referencing members of a @_versioned protocol
Protocol members can be directly referenced from protocol extensions
and generic functions. Since protocol members do not have accessibility
distinct from the protocol itself, ignore them, since they won't carry
the @_versioned attribute.

While workign on this I uncovered an interesting bug where we allow
members of protocol extensions to be more accessible than the protocol
itself, but then we give the symbols hidden visibility at the SIL level
anyway.

I filed <https://bugs.swift.org/browse/SR-3684> to track this issue.
2017-01-20 01:22:50 -08:00
Slava Pestov
d65d1d25f9 Sema: Diagnostics for @_inlineable, @_versioned and Swift 4 default arguments model
Piggybacks some resilience diagnostics onto the availability
checking code.

Public and versioned functions with inlineable bodies can only
reference other public and internal entities, since the SIL code
for the function body is serialized and stored as part of the
module.

This includes @_transparent functions, @_inlineable functions,
accessors for @_inlineable storage, @inline(__always) functions,
and in Swift 4 mode, default argument expressions.

The new checks are a source-breaking change, however we don't
guarantee source compatibility for underscored attributes.

The new ABI and tests for the default argument model will come in
subsequent commits.
2017-01-09 16:59:13 -08:00