Commit Graph

115 Commits

Author SHA1 Message Date
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