Skip to content

Commit 5dd6c4e

Browse files
committed
[NFC] Pass SIL-specific type resolution state abstractly into Sema
This is in preparation for parsing pack element archetypes.
1 parent f01bcce commit 5dd6c4e

File tree

11 files changed

+184
-78
lines changed

11 files changed

+184
-78
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5302,6 +5302,8 @@ NOTE(overridden_required_initializer_here,none,
53025302
// Functions
53035303
ERROR(attribute_requires_function_type,none,
53045304
"@%0 attribute only applies to function types", (StringRef))
5305+
ERROR(generic_function_type,none,
5306+
"function values cannot be generic", ())
53055307
ERROR(unsupported_convention,none,
53065308
"convention '%0' not supported", (StringRef))
53075309
ERROR(unreferenced_generic_parameter,NoUsage,

include/swift/AST/TypeCheckRequests.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,8 +3291,7 @@ class ModuleLibraryLevelRequest
32913291

32923292
class ResolveTypeRequest
32933293
: public SimpleRequest<ResolveTypeRequest,
3294-
Type(const TypeResolution *, TypeRepr *,
3295-
GenericParamList *),
3294+
Type(const TypeResolution *, TypeRepr *),
32963295
RequestFlags::Uncached> {
32973296
public:
32983297
using SimpleRequest::SimpleRequest;
@@ -3301,12 +3300,15 @@ class ResolveTypeRequest
33013300
// Cycle handling.
33023301
void noteCycleStep(DiagnosticEngine &diags) const;
33033302

3303+
static Type evaluate(const TypeResolution &resolution,
3304+
TypeRepr *repr);
3305+
33043306
private:
33053307
friend SimpleRequest;
33063308

33073309
// Evaluation.
33083310
Type evaluate(Evaluator &evaluator, const TypeResolution *resolution,
3309-
TypeRepr *repr, GenericParamList *silParams) const;
3311+
TypeRepr *repr) const;
33103312
};
33113313

33123314
void simple_display(llvm::raw_ostream &out, const TypeResolution *resolution);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===--- SILTypeResolutionContext.h -----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_SEMA_SILTYPERESOLUTIONCONTEXT_H
14+
#define SWIFT_SEMA_SILTYPERESOLUTIONCONTEXT_H
15+
16+
namespace swift {
17+
class GenericParamList;
18+
19+
class SILTypeResolutionContext {
20+
public:
21+
/// Are we requesting a SIL type?
22+
bool IsSILType;
23+
24+
/// Look up types in the given parameter list.
25+
GenericParamList *GenericParams;
26+
27+
SILTypeResolutionContext(bool isSILType,
28+
GenericParamList *genericParams)
29+
: IsSILType(isSILType), GenericParams(genericParams) {}
30+
};
31+
32+
}
33+
34+
#endif

include/swift/Subsystems.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace swift {
6464
class SerializationOptions;
6565
class SILOptions;
6666
class SILModule;
67+
class SILTypeResolutionContext;
6768
class SourceFile;
6869
enum class SourceFileKind;
6970
class SourceManager;
@@ -163,10 +164,9 @@ namespace swift {
163164
/// code completion).
164165
///
165166
/// \returns A well-formed type on success, or an \c ErrorType.
166-
Type performTypeResolution(TypeRepr *TyR, ASTContext &Ctx, bool isSILMode,
167-
bool isSILType,
167+
Type performTypeResolution(TypeRepr *TyR, ASTContext &Ctx,
168168
GenericSignature GenericSig,
169-
GenericParamList *GenericParams,
169+
SILTypeResolutionContext *SILContext,
170170
DeclContext *DC, bool ProduceDiagnostics = true);
171171

172172
/// Expose TypeChecker's handling of GenericParamList to SIL parsing.

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,8 @@ class CodeCompletionCallbacksImpl : public IDEInspectionCallbacks {
200200

201201
const auto ty = swift::performTypeResolution(
202202
ParsedTypeLoc.getTypeRepr(), P.Context,
203-
/*isSILMode=*/false,
204-
/*isSILType=*/false,
205203
CurDeclContext->getGenericSignatureOfContext(),
206-
/*GenericParams=*/nullptr,
204+
/*SILContext=*/nullptr,
207205
CurDeclContext,
208206
/*ProduceDiagnostics=*/false);
209207
if (!ty->hasError()) {

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ void swift::ide::collectPossibleReturnTypesFromContext(
254254
} else {
255255
const auto type = swift::performTypeResolution(
256256
CE->getExplicitResultTypeRepr(), DC->getASTContext(),
257-
/*isSILMode=*/false, /*isSILType=*/false,
258-
DC->getGenericSignatureOfContext(), /*GenericParams=*/nullptr,
257+
DC->getGenericSignatureOfContext(), /*SILContext=*/nullptr,
259258
const_cast<DeclContext *>(DC), /*diagnostics=*/false);
260259

261260
if (!type->hasError()) {

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/Parse/Lexer.h"
2828
#include "swift/Parse/ParseSILSupport.h"
2929
#include "swift/Parse/Parser.h"
30+
#include "swift/Sema/SILTypeResolutionContext.h"
3031
#include "swift/SIL/AbstractionPattern.h"
3132
#include "swift/SIL/InstructionUtils.h"
3233
#include "swift/SIL/SILArgument.h"
@@ -131,6 +132,7 @@ namespace {
131132
} // namespace
132133

133134
namespace swift {
135+
/// The parser for an individual SIL function.
134136
class SILParser {
135137
friend SILParserState;
136138
public:
@@ -1255,10 +1257,10 @@ Type SILParser::performTypeResolution(TypeRepr *TyR, bool IsSILType,
12551257
if (!GenericSig)
12561258
GenericSig = ContextGenericSig;
12571259

1258-
return swift::performTypeResolution(TyR, P.Context,
1259-
/*isSILMode=*/true, IsSILType,
1260-
GenericSig, GenericParams,
1261-
&P.SF);
1260+
SILTypeResolutionContext SILContext(IsSILType, GenericParams);
1261+
1262+
return swift::performTypeResolution(TyR, P.Context, GenericSig,
1263+
&SILContext, &P.SF);
12621264
}
12631265

12641266
/// Find the top-level ValueDecl or Module given a name.
@@ -7590,12 +7592,11 @@ static bool parseSILWitnessTableEntry(
75907592
if (TyR.isNull())
75917593
return true;
75927594

7595+
SILTypeResolutionContext silContext(/*isSILType=*/false,
7596+
witnessParams);
75937597
auto Ty =
75947598
swift::performTypeResolution(TyR.get(), P.Context,
7595-
/*isSILMode=*/false,
7596-
/*isSILType=*/false,
7597-
witnessSig,
7598-
witnessParams,
7599+
witnessSig, &silContext,
75997600
&P.SF);
76007601
if (witnessSig) {
76017602
Ty = witnessSig.getGenericEnvironment()->mapTypeIntoContext(Ty);
@@ -7655,11 +7656,11 @@ static bool parseSILWitnessTableEntry(
76557656
if (TyR.isNull())
76567657
return true;
76577658

7659+
SILTypeResolutionContext silContext(/*isSILType=*/false,
7660+
witnessParams);
76587661
auto Ty =
76597662
swift::performTypeResolution(TyR.get(), P.Context,
7660-
/*isSILMode=*/false,
7661-
/*isSILType=*/false,
7662-
witnessSig, witnessParams,
7663+
witnessSig, &silContext,
76637664
&P.SF);
76647665
if (witnessSig) {
76657666
Ty = witnessSig.getGenericEnvironment()->mapTypeIntoContext(Ty);

lib/SIL/Parser/SILParserState.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ namespace swift {
2525
class Parser;
2626
class SILModule;
2727

28+
/// The global state of the SIL parser that the ordinary parser needs to
29+
/// maintain while parsing a SIL file. Local state, like the value map of
30+
/// a SIL function, does not need to be kept here.
2831
class SILParserState : public SILParserStateBase {
2932
public:
3033
explicit SILParserState(SILModule &M) : M(M) {}

0 commit comments

Comments
 (0)