Commit Graph

418 Commits

Author SHA1 Message Date
Doug Gregor
8514225c58 [AST Verifier] Drop checks that don’t work with lazily-computed overrides. 2018-07-18 14:50:38 -07:00
Doug Gregor
5815a81922 [AST Verifier] Don’t ask to compute overridden declarations.
Don’t ask to compute overridden declarations that haven’t already been
computed.
2018-07-18 14:50:38 -07:00
Mark Lacey
7798b9f877 Partial fix for verification of where pointer conversions can appear.
The existing verification seems unnecessarily brittle, but this isn't
a general fix for that problem. This fixes one instance of where we
are generating perfectly valid pointer conversions that the verifier
is currently blowing up on.

I've opened https://bugs.swift.org/browse/SR-8264 to track reworking
this verification to not be quite so brittle.
2018-07-15 23:10:38 -07:00
Pavel Yaskevich
871a436d35 [ASTVerifier] Make sure that immediate paren/force-value is outside of load 2018-07-07 11:50:42 -07:00
Slava Pestov
381483bd74 AST: Remove Expr's LValueAccessKind 2018-07-05 23:54:13 -07:00
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Robert Widmann
a7c9bd09db Merge pull request #17181 from CodaFi/in-put-up-and-in-shut-up
[IDE] Scrub SwiftIDE of References to getInput()
2018-06-16 11:14:49 -07:00
John McCall
9022b5152f Rename accessor kinds from IsGetter -> IsGet, etc.
Introduce some metaprogramming of accessors and generally prepare
for storing less-structured accessor lists.

NFC except for a change to the serialization format.
2018-06-14 17:08:55 -04:00
Slava Pestov
296ce3f312 AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked
the ParamDecl's flags instead.
2018-06-13 15:38:52 -07:00
Robert Widmann
e8eba29cd9 [IDE] Scrub SwiftIDE of References to getInput() 2018-06-13 14:43:54 -07:00
Michael Gottesman
a264b1ed9c [gardening] Use SmallPtrSetImpl instead of SmallPtr<N> in more function parameters/return values.
This is good practice like using SmallVectorImpl instead of SmallVector.
2018-05-07 10:35:51 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Huon Wilson
b6d44f31da [AST] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:06 +10:00
Pavel Yaskevich
26905602f9 Merge pull request #16023 from xedin/rdar-36497404
[Serialization] Refactor normal conformance serialization
2018-04-20 00:05:23 -07:00
Pavel Yaskevich
01e8cbd23a [AST] Remove requiresSubstitution invariant from Witness 2018-04-19 18:13:06 -07:00
Jordan Rose
6a080d8c5c Disallow 'open let'
...and add a verifier check to make sure we don't mix 'open' and
'final' in the future.

You could /write/ 'open let' in Swift 4.1, but you couldn't actually
override such a property (within the module or outside). To maintain
source compatibility, this is just going to emit a warning before
Swift 5 (instead of an error), since it wasn't harming anything in
practice.
2018-04-18 16:48:10 -07:00
Jordan Rose
3cf00637fa AST-verify that 'open' is only used on classes and overridable members (#15996)
...and fix places where it was being used inappropriately.

- Don't use 'open' on non-class members in the importer.
- Use the existing 'copyFormalAccessFrom' instead of an ad hoc version
  for synthesized typealiases for protocol conformances. (This can
  change 'internal' down to 'fileprivate', but only where the
  enclosing type was already 'private' or 'fileprivate'.)
- Fix 'copyFormalAccessFrom' to not copy '@usableFromInline' onto
  declarations that don't support it (namely, the above typealiases).

This should have no visible effect in practice.
2018-04-18 16:47:54 -07:00
Doug Gregor
5674f5c7d7 [AST verifier] Remove the $.*lldb name-matching hack.
Once LLDB is setting the "debugger typealias" bit for its invariant-breaking
type aliases, we don't need this hack.
2018-03-26 16:50:50 -07:00
Doug Gregor
9aaa1f146a [AST] Skip verification of typealiases marked as "debugger aliases".
LLDB creates global typealiases that have archetypes in them, which
violates AST invariants and trips up the AST verifier. Introduce a specific
bit that LLDB can set to indicate that a given typealias is such an alias.
We'll skip AST verification for such typealiases.

As a way to stage in this change without requiring synchronization
across the Swift and LLDB repos, also match typealiases with the names
$.*lldb in the AST verifier and skip verification. Once LLDB is
setting the bit appropriately, we'll remove this hack.
2018-03-26 15:47:54 -07:00
Doug Gregor
f5fd678cf5 [AST Verifier] Temporarily disable an archetype context check.
Something in the interface between LLDB and Swift is causing this check to
fire. Disable it temporarily while we work on that interface.
2018-03-26 08:34:25 -07:00
Doug Gregor
5b302b76f9 [AST verifier] Only verify archetypes in the canonical type. 2018-03-25 20:46:07 -07:00
Doug Gregor
325fdd2f12 [AST] Don’t propagate all recursive properties to BoundNameAliasType.
With the exception of “has type variable”, which affects the arena used
for storage of a BoundNameAliasType, only propagate recursive properties
from the underlying type to a BoundNameAliasType, because the other
properties (e.g., “has archetype” or “has type parameter”) pulled from
syntactic sugar don’t apply.
2018-03-25 20:46:07 -07:00
Mark Lacey
85f25003ce Replace uses of getOptionalObjectType(bool &).
Instead, use the one that doesn't have a reference parameter.
2018-03-16 21:19:49 -07:00
Slava Pestov
11f949e5f1 Sema: Fix signature of materializeForSet with mutating getter and non-mutating setter
I admit this is an odd corner case that is unlikely to ever
come up in practice.

Fixes <rdar://problem/32860203>.
2018-03-10 03:39:08 -08:00
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Mark Lacey
2008674495 Make ImplicitlyUnwrappedOptional<T> an unavailable typealias.
Also remove the decl from the known decls and remove a
bunch of code referencing that decl as well as a bunch of other
random things including deserialization support.

This includes removing some specialized diagnostics code that
matched the identifier ImplicitlyUnwrappedOptional, and tweaking
diagnostics for various modes and various issues.

Fixes most of rdar://problem/37121121, among other things.
2018-02-02 08:35:53 -08:00
Mark Lacey
8d115b8e73 Revert "Allow inout arguments that differ in optionality than the expected parameter."
This partially reverts commit 8685ee01a1.

The tests are still in place, but the code change is no longer necessary
now that IUOs are removed from the type system.

Fixes: rdar://problem/37013789
2018-01-31 12:15:58 -08:00
Mark Lacey
8685ee01a1 Allow inout arguments that differ in optionality than the expected parameter.
Allow passing Optional<T> as inout where
ImplicitlyUnwrappedOptional<T> is expected, and vice-versa.

Swift 4.1 added a warning that overloading inouts by kind of optional
was deprecated and would be removed, but we didn't actually allow
people to remove an overload and pass arguments of the other kind of
optional to the remaining function.

Fixes rdar://problem/36913150
2018-01-29 15:07:44 -08: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
Mark Lacey
85c664d9ea IUO: Rework failability verification and fix a verification failure. 2018-01-06 17:24:43 -08:00
Mark Lacey
c3d195eb84 IUO: Strip specifier type in IUO attribute verification. 2018-01-03 19:12:11 -08:00
Mark Lacey
775547c3b4 IUO: Add verification of ImplicitlyUnwrappedOptionalAttr on ConstructorDecl. 2017-12-22 13:11:18 -08:00
Joe Groff
4b401e257a Merge pull request #12835 from jckarter/key-path-type-checking
Sema: Fixes for KeyPath type checking.
2017-11-14 13:10:44 -08:00
Joe Groff
73d2e9a47f Sema: Fixes for KeyPath type checking.
When testing KeyPathApplication constraints, we would keep going after rejecting a concrete KeyPath application by trying PartialKeyPath and AnyKeyPath, even though that's not what we want, since any key path application expression can type check with an AnyKeyPath. We would then miscompile by building the AST such that we applied the mismatched key path expression directly to the base. We also didn't handle expressions where the base was a subtype of the key path's base type correctly—the conversion means the base can't be written through in this situation, and we hardcoded the concrete-to-existential case instead of handling general conversions. Fix these problems, and add an AST verifier for KeyPathApplicationExprs to help catch problems in the future. Fixes SR-6300 | rdar://problem/35368903.
2017-11-09 11:57:23 -08:00
Mark Lacey
d83374449b Add a declaration attribute for implicitly unwrapped optional.
Attach this attribute to VarDecls declared as IUO, and to function decls
that have a result type that is an IUO.

NFC at the moment. Eventually we'll use these to determine where to
implicitly unwrap optional values.
2017-11-02 22:44:37 -07:00
Doug Gregor
6007783fa5 [AST Verifier] Eliminate “sharding” of AST verification.
The only client of this (the parse_stdlib) tests didn’t need it and
are no longer using it.
2017-11-01 16:07:25 -07:00
Slava Pestov
0f2da217a4 Sema: Fix some issues with overrides of materializeForSet
When overriding storage with a forced static dispatch materializeForSet,
the override's materializeForSet should not override the base
materializeForSet.

This is the case where a dynamic property witnesses a protocol
requirement, and Sema synthesizes a materializeForSet for it.

In this case, the synthesized materializeForSet dynamically dispatches
to the dynamic property's getter and setter, and the protocol witness
thunk directly calls the synthesized materializeForSet.

The subclass only needs to override the getter and setter in this case,
since the base class's materializeForSet will already do the right
thing.

In fact, marking it as an override exposes a problem where we cannot
serialize an xref to an imported property's materializeForSet, since
it was not created by the importer.
2017-10-26 17:11:09 -07:00
Slava Pestov
6def545696 AST: Remove GenericEnvironment::containsPrimaryArchetype()
This is no longer necessary now that archetypes refer back to a
GenericEnvironment.
2017-10-07 04:46:37 -07:00
David Zarzycki
61980167ef [ASTVerifier] Better DeferStmt checking 2017-10-05 14:38:36 -04:00
swift-ci
7dc2c706b8 Merge pull request #11874 from rjmccall/accessor-validation-noescape 2017-09-12 23:43:59 -07:00
John McCall
171d45d8c9 Move more of the signature validation of accessors into Sema.
Use this to remove the last bit of the hack to suppres noescape on setter
arguments.  Add a more comprehensive test of noescape's interaction with
accessors.
2017-09-13 01:11:00 -04:00
Slava Pestov
62d71d99e0 AST: Rename NormalProtocolConformance::Resolver to Loader
In almost all other places, 'resolver' means the ASTContext's LazyResolver,
which is just an abstract base class for the TypeChecker instance to break
circularity.

But here it is something totally different, used to lazily populate
imported and deserialized conformances, not parsed conformances.
2017-09-11 22:34:43 -07:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04:00
Jordan Rose
f8b7db4e76 Excise the terms "blacklist" and "whitelist" from Swift source. (#11687)
The etymology of these terms isn't about race, but "black" = "blocked"
and "white" = "allowed" isn't really a good look these days. In most
cases we weren't using these terms particularly precisely anyway, so
the rephrasing is actually an improvement.
2017-08-30 09:28:00 -07:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/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.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/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 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00