Commit Graph

321 Commits

Author SHA1 Message Date
Robert Widmann
4de729fffc [NFC] Add LookupConformancesInContextRequest
Add a request to lookup all implied conformances for use while
typechecking the primary. This provides a cache-point for
evaluator-based dependency tracking.
2020-03-26 10:26:25 -07:00
Robert Widmann
a9e11e3130 [NFC] Separate Taking Redundant Conformance Diagnostics From The Lookup Table 2020-03-24 12:40:11 -07:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
Saleem Abdulrasool
5e4017019b AST: remove invalid static_assert
This removes a set of static assertions that did not do what they were
supposed to do.

The static assertions were attempting to ensure that the functions are
different.  However, the address of a function is *not* a constant
expression and cannot be used in a static assertion.

Furthermore, the static assert is either tautologically true or will be
caught as a compile error on the dispatch.    The methods being checked
here are non-virtual.  The PFN that was being computed is tautologically
different as there is no virtuality and the two methods must be
different (barring any ICF coalescing that may be performed by the
linker or by LTO).  The method must exist, otherwise, the dispatch
itself will trigger a resolution failure.

Effectively, the static assertionss did not compute anything as a
result:
- the method's existence is checked by the dispatch
- the address of the function is always different

This was identified by building with GCC 7.
2019-12-26 16:53:46 -08:00
Robert Widmann
01d272073a Requestify Witness Resolution
Witness matching is a source of a lot of ad-hoc cycles, and mixes the
logic that performs resolution, caching, validation, and cycle detection into one
place.  To make matters worse, some checkers kick off other checks in
order to cache work for further declarations, and access an internal
cache on their subject conformance for many requirements at once, or
sometimes just one requirement.

None of this fits into the request evaluator's central view of the
caching.  This is further evidenced by the fact that if you attempt to
move the caching step into the evaluator, it overcaches the same
witness and trips asserts.

As a start, define requests for the resolution steps, and flush some
hacks around forcing witness resolution. The caching logic is mostly
untouched (the requests don't actually cache anything), but some cycle
breaking is now handled in the evaluator itself.  Once witness matching
has been refactored to cache with the evaluator, all of these hacks can
go away.

My urge to destroy the LazyResolver outweighs the compromises here.
2019-11-05 13:28:07 -08:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Robert Widmann
e7fccde40c Directly detect the cyclic case while computing conditional requirement
The general class of cycle here is when validation asks for the generic signature which triggers requirement checking which forces us to ask for the generic signature of the extension again.  We should look into a more principled solution.

See rdar://55263708
2019-09-20 20:38:38 -07:00
Slava Pestov
542d255b32 AST: ProtocolConformanceRef::subst() returns an invalid conformance instead of trapping
This is for consistency with Type::subst() which returns ErrorTypes.
2019-09-20 17:59:56 -04: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
e0a41b19cb Break some cycles
Computing the generic signature changes the way that cycles appear in the compiler.  For now, break these cycles.  We should investigate each place where hasComputedGenericSignature() is used in service of breaking cycles.  See rdar://55263708
2019-09-16 12:50:24 -07:00
Slava Pestov
a0e160e215 AST: Refactor Decl::isWeakImported() API a little bit
First, remove the AvailabilityContext parameter; it was confusing because
we actually always want to use the deployment target here.

Then, split this method up into three methods:

- isAlwaysWeakImported(): simply checks for a @_weakLinked attribute, either
  on the declaration itself or one of its parent contexts.

- getAvailabilityForLinkage(): returns the OS version availability when
  this declaration was introduced, or if the declaration does not have
  explicit availability, check it's storage (if its an accessor), or its
  parent contexts.

- isWeakImported(ModuleDecl *fromModule): combines these two checks to
  determine if the declaration should be weak linked when referenced from
  the given module, or if it might be weak referenced from some module
  (if the module parameter is null).
2019-09-06 20:08:40 -04:00
Slava Pestov
22cb6f1176 AST: Introduce ProtocolDecl::get{AssociatedType,ProtocolRequirement}() 2019-09-03 22:39:35 -04:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Slava Pestov
2df27a911a Sema: Remove TypeChecker::PartiallyCheckedConformances
Now that ensureRequirementsAreSatisfied() is never called with
failUnsubstituted == false, remove all the logic for deferring
checking of a conformance against the requirement signature of
its protocol.
2019-07-06 00:17:51 -04:00
Slava Pestov
6e7f7378b3 Sema: Use NormalProtocolConformance::finishSignatureConformances()
Previously we would call ensureRequirementsAreSatisfied() with the
failUnsubstituted parameter set to false. This would populate the
signature conformances and check the requirement signature in a
parsed conformance.

Sometimes, forming the substituted requirement types would fail,
and since failUnsubstituted was false the conformance would be
added to TypeChecker::PartiallyCheckedConformances.

Now, we use finishSignatureConformances() to lazily populate
the signature conformances when needed. This is always expected to
produce valid conformances.

ensureRequirementsAreSatisfied() is still called for conformances
in primary files, but it no longer writes to the signature
conformances array, and instead only diagnoses errors.
2019-07-06 00:16:36 -04:00
Slava Pestov
df8689128d AST: Move ClangImporter's finishSignatureConformances() to a method on NormalProtocolConformance
Also generalize the algorithm slightly to handle the full generality of
non-imported conformances.
2019-07-06 00:11:17 -04:00
Slava Pestov
a1905aa1da AST: Add ProtocolConformanceRef::mapConformanceOutOfContext() 2019-07-06 00:11:17 -04:00
Slava Pestov
ae5a427193 AST: Fix ProtocolConformance::getWitnessDeclRef()
This method was only ever called with non-generic witnesses,
because it assumed the substitutions stored in the witness
would always be derived from the conforming type.

There were two cases where this wasn't the case though:

1) If the witness is itself generic
2) The witness was defined in a protocol extension and the
   conforming type is a non-final class

In all cases, the SubstitutionMap stored in a Witness always
uses the 'synthetic environment'. In some cases, the
'synthetic environment' is the generic environment of the
witness. But in 1) and 2) it was different. While 1) never
occurred because we never used this method to look up
witnesses for generic requirements, 2) could happen.
2019-06-11 02:47:32 -07:00
Slava Pestov
6e90172010 AST: Remove unnecessary fast path 2019-06-11 02:47:32 -07:00
Slava Pestov
18f216c581 Sema: Fix re-entrant call to ensureRequirementsAreSatisfied() when resolving associated conformances
ConformanceChecker::ensureRequirementsAreSatisfied() modifies the
conformance as it resolves each one of its associated conformances,
so a re-entrant call can end up corrupting state by adding too
many elements to the buffer, or adding elements at the wrong
offsets.

If TypeChecker::checkConformanceRequirements() was called before
ConformanceChecker::resolveTypeWitnesses(), we could re-entrantly call
ConformanceChecker::ensureRequirementsAreSatisfied():

TypeChecker::checkConformanceRequirements()
=> ConformanceChecker::ensureRequirementsAreSatisfied()
   => Type::subst(), etc
      => ConformanceChecker::resolveTypeWitnesses()
         => ConformanceChecker::ensureRequirementsAreSatisfied()

The code in SubstitutionMap::lookupConformance() worked around
this by checking the failure condition and calling
resolveTypeWitness() first, before calling getAssociatedConformance().

Instead, remove this and call resolveTypeWitness() from inside
NormalProtocolConformance::getAssociatedConformance().
2019-05-28 22:08:31 -04:00
Slava Pestov
86f9ca7245 AST: Add ProtocolConformanceRef::getWitnessByName() 2019-05-14 21:18:06 -04:00
Slava Pestov
6e3609dc22 AST: ProtocolConformanceRef::getTypeWitnessByName() should be an instance method 2019-05-14 19:28:55 -04:00
Slava Pestov
4e3dafd9f7 AST: Remove ProtocolConformanceRef::getInheritedConformanceRef() 2019-05-10 15:00:49 -04:00
Slava Pestov
644b6adcd2 AST: Simplify ProtocolConformanceRef::getTypeWitnessByName() 2019-05-10 15:00:48 -04:00
Jordan Rose
517f5d6b6a [ClangImporter] Retire the term "adapter" in favor of "overlay" (#24427)
Way back in Swift 1 I was trying to draw a distinction between
"overlays", separate libraries that added Swift content to an existing
Objective-C framework, and "the Swift part of a mixed-source
framework", even though they're implemented in almost exactly the same
way. "Adapter module" was the term that covered both of those. In
practice, however, no one knew what "adapter" meant. Bring an end to
this confusion by just using "overlay" within the compiler even for
the mixed-source framework case.

No intended functionality change.
2019-05-03 11:11:58 -07:00
Arnold Schwaighofer
768d1c51a1 Address review feedback 2019-05-01 09:31:07 -07:00
Arnold Schwaighofer
a793dfb451 Respect resilience when specializing opaque type archetypes 2019-05-01 09:31:07 -07:00
Joe Groff
e3bbd8ce9e Remove ResilienceExpansion from substOpaqueTypes for now.
It's currently meaningless, and it'll require thought to pass the correct value when it becomes
meaningful.
2019-04-17 14:43:32 -07:00
Joe Groff
a419754fe9 Support nested types on opaque archetypes (and maybe opened ones). 2019-04-17 14:43:32 -07:00
Joe Groff
c771a7e71b SILGen: Substitute away opaque types. 2019-04-17 14:43:32 -07:00
Slava Pestov
5062a81e3d AST: Start returning SelfProtocolConformances from ModuleDecl::lookupConformance()
Fixes <rdar://problem/49241923>, <https://bugs.swift.org/browse/SR-10015>.
2019-04-16 23:02:50 -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
69d1cafd1c AST: Add AvailabilityContext parameter to Decl::isWeakImported()
For now, it's not used, but we do try to pass the right value down from
our various call sites.

Progress on <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Doug Gregor
d31ef61a28 Eliminate "sorting" of DeclContext-local protocols / conformances.
Sorting of DeclContext-local protocols and conformances shouldn't ever
be necessary, because the underlying data structures that produce
these lists should be deterministic. Sorting can hide any
non-determinism, so stop doing it and we can address the underlying
nondeterminism.
2019-02-15 14:16:48 -08:00
Doug Gregor
5757d14365 Don’t add RawRepresentation conformance for enums with erroneous raw types
This avoids cascading errors with very unfortunate Fix-Its.
rdar://problem/47891507
2019-02-12 23:12:17 -08:00
Slava Pestov
aa747dcd81 Remove property behaviors 2018-12-07 20:38:33 -05:00
Argyrios Kyrtzidis
7653ccea54 [AST] minor nitpick in ProtocolConformance.cpp: the 'getASTContext().getClangModuleLoader()' call seems redundant 2018-12-07 10:24:33 -08:00
Argyrios Kyrtzidis
9405f1eb09 [AST] Break dependency cycle between swiftAST and swiftClangImporter
NormalProtocolConformance::isRetroactive() introduces dependency on swiftClangImporter by calling ClangModuleUnit::getAdapterModule().
Do some refactoring to break the cycle.
2018-12-06 22:54:33 -08:00
swift-ci
39161d5b36 Merge pull request #20600 from adrian-prantl/36032653 2018-12-05 17:01:58 -08:00
John McCall
8112f68b96 Merge pull request #20629 from rjmccall/error-self-conformance
Allow Error to conform to itself
2018-12-05 19:58:08 -05:00
Adrian Prantl
d63debeb60 Experimental: Extend ClangImporter to import clang modules from DWARF
When debugging Objective-C or C++ code on Darwin, the debug info
collected by dsymutil in the .dSYM bundle is entirely
self-contained. It is possible to debug a program, set breakpoints and
print variables even without having the complete original source code
or a matching SDK available. With Swift, this is currently not the
case. Even though .dSYM bundles contain the binary .swiftmodule for
all Swift modules, any Clang modules that the Swift modules depend on,
still need to be imported from source to even get basic LLDB
functionality to work. If ClangImporter fails to import a Clang
module, effectively the entire Swift module depending on it gets
poisoned.

This patch is addressing this issue by introducing a ModuleLoader that
can ask queries about Clang Decls to LLDB, since LLDB knows how to
reconstruct Clang decls from DWARF and clang -gmodules producxes full
debug info for Clang modules that is embedded into the .dSYM budle.

This initial version does not contain any advanced functionality at
all, it merely produces an empty ModuleDecl. Intertestingly, even this
is a considerable improvement over the status quo. LLDB can now print
Swift-only variables in modules with failing Clang depenecies, and
becuase of fallback mechanisms that were implemented earlier, it can
even display the contents of pure Objective-C objects that are
imported into Swift. C structs obviously don't work yet.

rdar://problem/36032653
2018-12-05 13:54:13 -08:00
Slava Pestov
cc3730f410 AST: A conformance is weak-linked if its protocol, conforming type or extension is @_weakLinked
Fixes <rdar://problem/46316197>.
2018-12-03 20:36:03 -05:00
John McCall
49ba9c59d1 Allow Error to conform to itself.
Most of the foundation for this was laid in earlier patches.
2018-11-17 02:51:45 -05:00
John McCall
72e5fc2276 Fix a source-compatibility bug in #20658.
Test is in #20629.
2018-11-17 02:49:40 -05:00
John McCall
cd2b558280 Fix a bug with inlining self-conformances. 2018-11-16 22:59:12 -05:00
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Doug Gregor
6fd878c2b3 [Sema] Lazily fill in signature conformances as needed.
If the type checker doesn't prepopulate signature conformances, fill
them in when we first need them. This is a stopgap solution until we
can move these queries over to the request-evaluator.

Fixes rdar://problem/34584596, as well as a regression introduced by
the use of mangled names for associated conformances in witness tables.
2018-11-12 09:42:51 -08:00