Commit Graph

753 Commits

Author SHA1 Message Date
Doug Gregor
24d24c0e63 [AST] Allocate GenericSignature(Builders) in the arena
Opaque result type archetypes can involve type variables, which
then get introduced into GenericSignatureBuilders and the
generated GenericSignatures. Allocate them in the proper arena
So we don’t end up with use-after-free errors.

Fixes rdar://problem/50309503.
2019-05-07 06:56:42 -07:00
Alexis Laferrière
1119b91e80 Merge pull request #24204 from xymus/structural-type-request
GSB: use a request for the structural type of type aliases
2019-04-30 14:39:39 -07:00
Alexis Laferrière
bddb40dacf GSB: ignore generic types in expandConformanceRequirement
Fixes crashes in 28437-swift-typechecker-validatedecl.swift (from previous commit)
and the compiler crasher 28861-gpdecl-getdepth-generictypeparamdecl-
invaliddepth-parameter-hasnt-been-validated.swift.
2019-04-30 10:43:23 -07:00
Slava Pestov
fa12d85739 AST: Clean up associated type default representation a bit 2019-04-26 21:47:02 -04:00
Alexis Laferrière
5bbf06c3d5 Sema: use the underlying type when available instead of the structural type request
The underlying type may have been set on a validated type alias or when deserialized.
2019-04-25 14:38:11 -07:00
Alexis Laferrière
a315e44616 GSB: use StructuralTypeRequest for type aliases 2019-04-25 10:22:05 -07:00
Slava Pestov
ce70083bee GSB: Clean up resolveDeclSignature() calls 2019-04-19 16:50:29 -04:00
Saleem Abdulrasool
fb8eabe7b6 AST: switch to std::sort from llvm::array_pod_sort
Swap the `array_pod_sort` to `sort`.  `array_pod_sort` is meant to be
used with POD types only.  Switching to `std:sort` should be slightly
faster, and more importantly, allows the emission of the warnings on
Windows to be sorted identically to Linux and macOS.
2019-03-27 22:03:29 -07:00
David Zarzycki
236a0dcfe2 Revert "[GSB] NFC: Precompute or cache DependentMemberType when possible"
This reverts commit 8876c9e78f, which has
a memory leak.
2019-03-06 10:01:37 -05:00
David Zarzycki
515a767a37 [GSB] NFC: delete dead code
Potential archetypes with parents always have AssociatedTypeDecls.
2019-03-04 09:13:24 -05:00
David Zarzycki
8876c9e78f [GSB] NFC: Precompute or cache DependentMemberType when possible
Calling DependentMemberType::get() repeatedly pollutes the processor
caches because the global hash table can be quite large. With this
change, we either precompute DependentMemberTypes or cache them on
demand. This change makes the release/no-assert build of
Swift.swiftmodule 4.1% faster.
2019-03-02 10:14:49 -05:00
Joe Groff
0cfca9496a Give opened archetypes a generic environment.
And maybe allow nested types to live on them.
2019-02-20 12:52:48 -08:00
Doug Gregor
3b0c3c21a9 Merge pull request #22622 from DougGregor/gsb-infer-nested-type-name-match
[GSB] Consistently use nested type name match constraints.
2019-02-14 20:03:05 -08:00
Doug Gregor
af335c6bb9 [GSB] Consistently use nested type name match constraints.
We generated a mix of "inferred" and "nested type name match"
constraints for the case where we had two nested types with the same
name and inferred that they are equal. Make them consistent by always
using nested type name match constraints. This fixes a bug where we
would get different canonical generic signatures in different source
files because we inferred the same-type constraint with different
requirement sources.

Fixes rdar://problem/48049725.
2019-02-14 14:28:43 -08:00
Suyash Srijan
60da82b70d [GSB] [Diag] Constraint to concrete type using ":" should offer a fix-it (#22152)
* [diag] add a diagnostic note for the fixit

* [gsb] emit a diagnostic with fixit to replace ':' with '=='

* [gsb] rename variable

* [gsb] replace dyn_cast with isa

* [test] add a test case

* [test] update tests

* [gsb] emit diagnostic for protocols as well

* [gsb] simplify if statement

* [gsb] rename a variable

* [gsb] Create a helper to remove Self. prefix and add a new test case

* [gsb] simplify checks

* [gsb] move the diagnostic code to finalize()

* [gsb] re-indent

* [gsb] fix a typo

* [gsb] pass values as copy

* [gsb] show a fixit if the subject type is a member type

* [test] update diagnostics in existing tests

* [gsb] check if the subject type has an assoc type decl

* [gsb] use requirement source

* [test] add new tests

* [gsb] use constraint struct and rename to invalidIsaConstraints
2019-02-08 11:02:32 -05:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Slava Pestov
98287ca239 AST: Fix failure to diagnose with redundant same-type constraints
This test case used to crash because the source-location-based order
here did not handle invalid source locations, but Doug fixed it already
in #21656. However, fixing it to sort invalid locations after valid
locations meant that the diagnostic code would pick the invalid location
to emit the diagnostic on, so no diagnostic was emitted.

This is not a big deal since the diagnostics in question are warnings,
but we do want to emit these redundant constraint warnings to avoid
confusing users if possible so let's fix it to do the right thing.

More completely fixes rdar://problem/46848889 (but it was already not
crashing after Doug's fix).
2019-01-07 21:31:58 -05:00
swift-ci
4544476851 Merge pull request #21656 from DougGregor/gsb-source-invalid-source-locs 2019-01-04 21:54:47 -08:00
Doug Gregor
05fc089af6 [Generic Signature Builder] Sort invalid source locations properly.
Fixes SR-9496 / rdar://problem/46699008.
2019-01-04 20:56:43 -08:00
Doug Gregor
e3729f444a Revert "[GSB] When adding same-type requirements pick representative based on canonical order"
This reverts commit c725660cc9. It
uncovered a use-after-free in the GenericSignatureBuilder. Apologies
for the lack of a test case here; I'm still looking for something
small enough to commit.

Fixes rdar://problem/46772328.
2018-12-21 09:44:48 -08:00
Doug Gregor
3406307252 [GSB] Move local header inclusions to the top.
Thanks, Jordan. NFC
2018-12-17 10:24:18 -08:00
Doug Gregor
fc7eb0d3b6 [AST] Pull GenericSignature::ResolvedType definition into a header.
We’re going to need to use this in GenericSignature.cpp. NFC
2018-12-17 09:22:10 -08:00
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08:00
Slava Pestov
bc4aa75b35 AST: Simplify GenericSignatureBuilder::computeRequirementSignature() 2018-12-11 23:55:41 -05:00
Pavel Yaskevich
d2d8f705c7 Merge pull request #20646 from xedin/rdar-45957015
[GSB] When adding same-type requirements pick representative based on…
2018-11-26 18:04:35 -08:00
Jordan Rose
1f25ea51d7 Fix two issues with typealiases in protocol extensions (#20654)
- The GenericSignatureBuilder assumed it didn't have to look in
  protocol extensions to resolve member types.

- Serialization was incorrectly filtering out such typealiases when
  trying to resolve a cross-module reference to one.

rdar://problem/46103190
2018-11-26 11:31:12 -08:00
Pavel Yaskevich
439784d54a [GSB/Diagnostics] Use llvm::array_pod_sort to sort "as written" edges
Instead of using `std::sort`, transform source-ordered edge vector
to reference `IntercomponentEdge *` instead of their indices in
`intercomponentEdges` vector and use `llvm::array_pod_sort` to sort them.
2018-11-26 11:20:54 -08:00
Pavel Yaskevich
ab3d1f54e1 [GSB/Diagnostics] Improve redundant same-type constraint diagnostics 2018-11-24 00:19:34 -08:00
Pavel Yaskevich
c725660cc9 [GSB] When adding same-type requirements pick representative based on canonical order
Instead of trying to order based on the "nested depth", let's
always prefer canonical ordering of type parameters when it comes
to picking representative equivalence class.

Resolves: rdar://problem/45957015
2018-11-23 00:08:14 -08:00
Slava Pestov
7ffe361709 Sema: Clean up generic signature checking 2018-11-16 01:18:18 -05:00
Pavel Yaskevich
a21990f3f6 [GSB] NFC: Couple of minor cleanups
- getOrCreateRewriteTreeRoot can't fail (unless it fails to allocate memory)
- mark `equivClass2` as modified as per original comment
2018-11-15 00:33:57 -08:00
Slava Pestov
add4185b83 AST: Fix infinite recursion with recursive same-type constraints
We diagnose and flag these in finalize(), but we can encounter one
even earlier through resolveDependentMemberTypes(). Do the same
thing there that we already do in EquivalenceClass::getTypeInContext().

Fixes <rdar://problem/45328122>, <https://bugs.swift.org/browse/SR-9022>.
2018-10-28 23:30:19 -04:00
Slava Pestov
7edbbae5c7 GSB: When merging two equivalence classes, don't forget to re-process delayed requirements
Fixes <rdar://problem/45307061>.
2018-10-16 17:01:02 -07:00
Slava Pestov
8acc11f80c Sema: Fix ambiguity resolution when doing unqualified lookup of associated types and type aliases
In structural lookup mode, let's resolve protocol typealiases to
dependent member types also. This is because areSameType() has
no way to see if a type alias is going to be equal to another
associated type with the same name, and so it would return false,
which produced ambiguity errors when there should not be any.

This exposes a deficiency in how we diagnose same-type constraints
where both sides are concrete. Instead of performing the check on
the requirement types, which might be dependent member types that
later on resolve to concrete types, do the check on the actual
equivalence classes further down in the GSB instead.

However, this in turn produces bogus diagnostics in some recursive
cases where we add same-type constraints twice for some reason,
resulting in a warning the second time around. Refine the check by
adding a new predicate to FloatingRequirementSource for requirements
that are explicitly written in source... which is not what
isExplicit() currently means.
2018-10-15 01:52:11 -07:00
Slava Pestov
9d131fd5f1 Merge pull request #18999 from hamishknight/location-by-association
[GSB] Avoid emitting associated type diagnostics on the protocol decl
2018-10-13 15:16:40 -07:00
Slava Pestov
b0009b6f7b GenericSignatureBuilder: Remove unnecessary null check 2018-10-12 03:06:52 -07:00
Slava Pestov
a8688b55e0 AST: Don't load unnecessary lazy generic environment in GenericSignatureBuilder::inferRequirements() 2018-09-26 23:24:14 -07:00
Graydon Hoare
14db5d2285 [AST] Add and use NominalTypeDecl::LookupDirectFlags rather than booleans. 2018-09-21 14:34:26 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Hamish Knight
42dc4ca342 [GSB] Remove getColonLoc() and getEqualLoc() in favour of getSeparatorLoc()
Most callers aren't concerned about the difference between the two (and those that are are already exercising the appropriate assertions with e.g the use of `getFirstType()`).
2018-09-06 16:40:07 +01:00
Doug Gregor
fafa9ed2d5 [GSB] ‘override’ keyword suppresses redeclaration warnings for assoc types. 2018-09-05 13:51:26 -07:00
Doug Gregor
e670ac42d9 Add command-line option -warn-implicit-overrides.
When provided, this flag warns about implicit overrides, where a
declaration overrides another declaration but is not marked with the
‘override’ keyword. The warning can be suppressed by either providing
‘override’ or ‘@_nonoverride’.

At present, this only happens with overrides in protocols.
2018-09-04 16:42:06 -07:00
Hamish Knight
819a13e880 [GSB] Avoid emitting associated type diagnostics on the protocol decl
For explicit abstract protocol floating requirement sources, get the source location from the protocol requirement rather than delegating to the parent `RequirementSource`.
2018-08-27 18:39:04 +01:00
Hamish Knight
7c5fbf2710 NFC: Remove a few unnecessary TypeLoc::withoutLoc()s 2018-08-27 13:23:42 +01:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Doug Gregor
3c54886c4d [Type checker] Use RequirementRequest::visitRequirements() more intentionally.
Rather than using RequirementRequest::visitRequirements() for its side
effects, then reading from the TypeLocs left behind, start eliminating
TypeLoc-based APIs so we pass Type and TypeRepr separately.

Add some utilities to dig into a possibly-null RequirementRepr* and dig
out the appropriate TypeReprs.
2018-08-23 15:14:19 -07:00
Doug Gregor
868f763406 [GSB] Ensure that we don’t pick a self-recursive requirement source.
When computing the conformance access path, make sure that we don’t pick
a self-recursive requirement source.
2018-08-23 14:20:25 -07:00
Doug Gregor
fcfd4c8a8c [Type checker] Introduce a request to evaluate “where” clause requirements.
Introduce a new form of request that produces the ith Requirement of the
where clause of a given entity, which could be a protocol, associated type,
or anything with generic parameters. The requirement can be evaluated
at any type resolution stage; the “interface” type stage will be cached
in the existing RequirementReprs.

Fixes SR-8119 / rdar://problem/41498944.
2018-08-23 09:25:58 -07:00
Doug Gregor
4b80872d48 [Type checker] Introduce stages for inherited type requests.
Extend the inputs to InheritedTypeRequest, SuperclassTypeRequest, and
EnumRawTypeRequest to also take a TypeResolutionStage, describing what
level of type checking is required. The GenericSignatureBuilder relies
only on structural information, while other clients care about the
full interface type.

Only the full interface type will be cached, and the contextual type
(if requested) will depend on that.
2018-08-22 15:29:08 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00