Skip to content

Commit d62ead5

Browse files
committed
---
yaml --- r: 348511 b: refs/heads/master c: 397ff4c h: refs/heads/master i: 348509: b02d40f 348507: 6027b3f 348503: aac7f3c 348495: 0284823 348479: 9f2f4b7
1 parent 06d5c26 commit d62ead5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+471
-391
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: aa7fa85a3734a7d52b622efd5f6efee828061ce9
2+
refs/heads/master: 397ff4ce051fb2f775fe5a25a9f01ddc68a43798
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,10 +4193,6 @@ class SILBoxType final : public TypeBase, public llvm::FoldingSetNode
41934193
SILLayout *getLayout() const { return Layout; }
41944194
SubstitutionMap getSubstitutions() const { return Substitutions; }
41954195

4196-
// In SILType.h:
4197-
CanType getFieldLoweredType(SILModule &M, unsigned index) const;
4198-
SILType getFieldType(SILModule &M, unsigned index) const;
4199-
42004196
// TODO: SILBoxTypes should be explicitly constructed in terms of specific
42014197
// layouts. As a staging mechanism, we expose the old single-boxed-type
42024198
// interface.

trunk/include/swift/Frontend/Frontend.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class SerializedModuleLoader;
5555
class MemoryBufferSerializedModuleLoader;
5656
class SILModule;
5757

58+
namespace Lowering {
59+
class TypeConverter;
60+
}
61+
5862
/// The abstract configuration of the compiler, including:
5963
/// - options for all stages of translation,
6064
/// - information about the build environment,
@@ -372,6 +376,7 @@ class CompilerInstance {
372376
SourceManager SourceMgr;
373377
DiagnosticEngine Diagnostics{SourceMgr};
374378
std::unique_ptr<ASTContext> Context;
379+
std::unique_ptr<Lowering::TypeConverter> TheSILTypes;
375380
std::unique_ptr<SILModule> TheSILModule;
376381

377382
std::unique_ptr<PersistentParserState> PersistentState;
@@ -422,8 +427,6 @@ class CompilerInstance {
422427

423428
bool isWholeModuleCompilation() { return PrimaryBufferIDs.empty(); }
424429

425-
void createSILModule();
426-
427430
public:
428431
// Out of line to avoid having to import SILModule.h.
429432
CompilerInstance();
@@ -448,6 +451,10 @@ class CompilerInstance {
448451
SILOptions &getSILOptions() { return Invocation.getSILOptions(); }
449452
const SILOptions &getSILOptions() const { return Invocation.getSILOptions(); }
450453

454+
Lowering::TypeConverter &getSILTypes();
455+
456+
void createSILModule();
457+
451458
void addDiagnosticConsumer(DiagnosticConsumer *DC) {
452459
Diagnostics.addConsumer(*DC);
453460
}

trunk/include/swift/SIL/Projection.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,7 @@ class Projection {
292292
///
293293
/// WARNING: This is not a constant time operation because it is implemented
294294
/// in terms of getVarDecl, which requests all BaseType's stored properties.
295-
SILType getType(SILType BaseType, SILModule &M) const {
296-
assert(isValid());
297-
switch (getKind()) {
298-
case ProjectionKind::Struct:
299-
case ProjectionKind::Class:
300-
return BaseType.getFieldType(getVarDecl(BaseType), M);
301-
case ProjectionKind::Enum:
302-
return BaseType.getEnumElementType(getEnumElementDecl(BaseType), M);
303-
case ProjectionKind::Box:
304-
return BaseType.castTo<SILBoxType>()->getFieldType(M, getIndex());
305-
case ProjectionKind::Tuple:
306-
return BaseType.getTupleElementType(getIndex());
307-
case ProjectionKind::Upcast:
308-
case ProjectionKind::RefCast:
309-
case ProjectionKind::BitwiseCast:
310-
case ProjectionKind::TailElems:
311-
return getCastType(BaseType);
312-
case ProjectionKind::Index:
313-
// Index types do not change the underlying type.
314-
return BaseType;
315-
}
316-
317-
llvm_unreachable("Unhandled ProjectionKind in switch.");
318-
}
295+
SILType getType(SILType BaseType, SILModule &M) const;
319296

320297
VarDecl *getVarDecl(SILType BaseType) const {
321298
assert(isValid());

trunk/include/swift/SIL/SILBuilder.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,13 +1746,7 @@ class SILBuilder {
17461746
getSILDebugLocation(Loc), valueType, operand));
17471747
}
17481748
ProjectBoxInst *createProjectBox(SILLocation Loc, SILValue boxOperand,
1749-
unsigned index) {
1750-
auto boxTy = boxOperand->getType().castTo<SILBoxType>();
1751-
auto fieldTy = boxTy->getFieldType(getModule(), index);
1752-
1753-
return insert(new (getModule()) ProjectBoxInst(
1754-
getSILDebugLocation(Loc), boxOperand, index, fieldTy));
1755-
}
1749+
unsigned index);
17561750
ProjectExistentialBoxInst *createProjectExistentialBox(SILLocation Loc,
17571751
SILType valueTy,
17581752
SILValue boxOperand) {

trunk/include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *Inst) {
20892089
remapOpenedType(cast<OpenedArchetypeType>(openedType));
20902090

20912091
if (!Inst->getOperand()->getType().canUseExistentialRepresentation(
2092-
Inst->getModule(), ExistentialRepresentation::Class)) {
2092+
ExistentialRepresentation::Class)) {
20932093
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
20942094
recordClonedInstruction(Inst, getBuilder().createOpenExistentialMetatype(
20952095
getOpLocation(Inst->getLoc()),

trunk/include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,9 +1643,7 @@ class AllocBoxInst final
16431643
bool hasDynamicLifetime() const { return dynamicLifetime; }
16441644

16451645
// Return the type of the memory stored in the alloc_box.
1646-
SILType getAddressType() const {
1647-
return getBoxType()->getFieldType(getModule(), 0).getAddressType();
1648-
}
1646+
SILType getAddressType() const;
16491647

16501648
/// Return the underlying variable declaration associated with this
16511649
/// allocation, or null if this is a temporary allocation.

trunk/include/swift/SIL/SILModule.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ class SILModule {
260260

261261
// Intentionally marked private so that we need to use 'constructSIL()'
262262
// to construct a SILModule.
263-
SILModule(ModuleDecl *M, SILOptions &Options, const DeclContext *associatedDC,
263+
SILModule(ModuleDecl *M, Lowering::TypeConverter &TC,
264+
SILOptions &Options, const DeclContext *associatedDC,
264265
bool wholeModule);
265266

266267
SILModule(const SILModule&) = delete;
@@ -313,7 +314,7 @@ class SILModule {
313314
void serialize();
314315

315316
/// This converts Swift types to SILTypes.
316-
mutable Lowering::TypeConverter Types;
317+
Lowering::TypeConverter &Types;
317318

318319
/// Invalidate cached entries in SIL Loader.
319320
void invalidateSILLoaderCaches();
@@ -340,12 +341,14 @@ class SILModule {
340341
/// If a source file is provided, SIL will only be emitted for decls in that
341342
/// source file.
342343
static std::unique_ptr<SILModule>
343-
constructSIL(ModuleDecl *M, SILOptions &Options, FileUnit *sf = nullptr);
344+
constructSIL(ModuleDecl *M, Lowering::TypeConverter &TC,
345+
SILOptions &Options, FileUnit *sf = nullptr);
344346

345347
/// Create and return an empty SIL module that we can
346348
/// later parse SIL bodies directly into, without converting from an AST.
347349
static std::unique_ptr<SILModule>
348-
createEmptyModule(ModuleDecl *M, SILOptions &Options,
350+
createEmptyModule(ModuleDecl *M, Lowering::TypeConverter &TC,
351+
SILOptions &Options,
349352
bool WholeModule = false);
350353

351354
/// Get the Swift module associated with this SIL module.

trunk/include/swift/SIL/SILType.h

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,29 @@ class SILType {
228228
/// something of unknown size.
229229
///
230230
/// This is equivalent to, but possibly faster than, calling
231-
/// M.Types.getTypeLowering(type).isAddressOnly().
232-
static bool isAddressOnly(CanType T, SILModule &M,
233-
CanGenericSignature Sig,
234-
ResilienceExpansion Expansion);
231+
/// tc.getTypeLowering(type).isAddressOnly().
232+
static bool isAddressOnly(CanType type, Lowering::TypeConverter &tc,
233+
CanGenericSignature sig,
234+
ResilienceExpansion expansion);
235+
235236
/// Return true if this type must be returned indirectly.
236237
///
237238
/// This is equivalent to, but possibly faster than, calling
238-
/// M.Types.getTypeLowering(type).isReturnedIndirectly().
239-
static bool isFormallyReturnedIndirectly(CanType type, SILModule &M,
240-
CanGenericSignature Sig) {
241-
return isAddressOnly(type, M, Sig, ResilienceExpansion::Minimal);
239+
/// tc.getTypeLowering(type).isReturnedIndirectly().
240+
static bool isFormallyReturnedIndirectly(CanType type,
241+
Lowering::TypeConverter &tc,
242+
CanGenericSignature sig) {
243+
return isAddressOnly(type, tc, sig, ResilienceExpansion::Minimal);
242244
}
243245

244246
/// Return true if this type must be passed indirectly.
245247
///
246248
/// This is equivalent to, but possibly faster than, calling
247-
/// M.Types.getTypeLowering(type).isPassedIndirectly().
248-
static bool isFormallyPassedIndirectly(CanType type, SILModule &M,
249-
CanGenericSignature Sig) {
250-
return isAddressOnly(type, M, Sig, ResilienceExpansion::Minimal);
249+
/// tc.getTypeLowering(type).isPassedIndirectly().
250+
static bool isFormallyPassedIndirectly(CanType type,
251+
Lowering::TypeConverter &tc,
252+
CanGenericSignature sig) {
253+
return isAddressOnly(type, tc, sig, ResilienceExpansion::Minimal);
251254
}
252255

253256
/// True if the type, or the referenced type of an address type, is loadable.
@@ -324,15 +327,13 @@ class SILType {
324327
/// representation kind for the type. Returns None if the type is not an
325328
/// existential type.
326329
ExistentialRepresentation
327-
getPreferredExistentialRepresentation(SILModule &M,
328-
Type containedType = Type()) const;
330+
getPreferredExistentialRepresentation(Type containedType = Type()) const;
329331

330332
/// Returns true if the existential type can use operations for the given
331333
/// existential representation when working with values of the given type,
332334
/// or when working with an unknown type if containedType is null.
333335
bool
334-
canUseExistentialRepresentation(SILModule &M,
335-
ExistentialRepresentation repr,
336+
canUseExistentialRepresentation(ExistentialRepresentation repr,
336337
Type containedType = Type()) const;
337338

338339
/// True if the type contains a type parameter.
@@ -394,11 +395,15 @@ class SILType {
394395
/// the given field. Applies substitutions as necessary. The
395396
/// result will be an address type if the base type is an address
396397
/// type or a class.
398+
SILType getFieldType(VarDecl *field, Lowering::TypeConverter &TC) const;
399+
397400
SILType getFieldType(VarDecl *field, SILModule &M) const;
398401

399402
/// Given that this is an enum type, return the lowered type of the
400403
/// data for the given element. Applies substitutions as necessary.
401404
/// The result will have the same value category as the base type.
405+
SILType getEnumElementType(EnumElementDecl *elt, Lowering::TypeConverter &TC) const;
406+
402407
SILType getEnumElementType(EnumElementDecl *elt, SILModule &M) const;
403408

404409
/// Given that this is a tuple type, return the lowered type of the
@@ -437,19 +442,29 @@ class SILType {
437442
/// generic args with the appropriate item from the substitution.
438443
///
439444
/// Only call this with function types!
445+
SILType substGenericArgs(Lowering::TypeConverter &TC,
446+
SubstitutionMap SubMap) const;
447+
440448
SILType substGenericArgs(SILModule &M,
441449
SubstitutionMap SubMap) const;
442450

443451
/// If the original type is generic, pass the signature as genericSig.
444452
///
445453
/// If the replacement types are generic, you must push a generic context
446454
/// first.
447-
SILType subst(SILModule &silModule, TypeSubstitutionFn subs,
455+
SILType subst(Lowering::TypeConverter &tc, TypeSubstitutionFn subs,
448456
LookupConformanceFn conformances,
449457
CanGenericSignature genericSig = CanGenericSignature(),
450458
bool shouldSubstituteOpaqueArchetypes = false) const;
451459

452-
SILType subst(SILModule &silModule, SubstitutionMap subs) const;
460+
SILType subst(SILModule &M, TypeSubstitutionFn subs,
461+
LookupConformanceFn conformances,
462+
CanGenericSignature genericSig = CanGenericSignature(),
463+
bool shouldSubstituteOpaqueArchetypes = false) const;
464+
465+
SILType subst(Lowering::TypeConverter &tc, SubstitutionMap subs) const;
466+
467+
SILType subst(SILModule &M, SubstitutionMap subs) const;
453468

454469
/// Return true if this type references a "ref" type that has a single pointer
455470
/// representation. Class existentials do not always qualify.
@@ -560,7 +575,7 @@ NON_SIL_TYPE(LValue)
560575
#undef NON_SIL_TYPE
561576

562577
CanSILFunctionType getNativeSILFunctionType(
563-
SILModule &M, Lowering::AbstractionPattern origType,
578+
Lowering::TypeConverter &TC, Lowering::AbstractionPattern origType,
564579
CanAnyFunctionType substType,
565580
Optional<SILDeclRef> origConstant = None,
566581
Optional<SILDeclRef> constant = None,
@@ -581,17 +596,24 @@ static inline llvm::hash_code hash_value(SILType V) {
581596
return llvm::hash_value(V.getOpaqueValue());
582597
}
583598

584-
inline SILType SILBoxType::getFieldType(SILModule &M, unsigned index) const {
585-
return SILType::getPrimitiveAddressType(getFieldLoweredType(M, index));
586-
}
587-
588599
inline SILType SILField::getAddressType() const {
589600
return SILType::getPrimitiveAddressType(getLoweredType());
590601
}
591602
inline SILType SILField::getObjectType() const {
592603
return SILType::getPrimitiveObjectType(getLoweredType());
593604
}
594605

606+
CanType getSILBoxFieldLoweredType(SILBoxType *type,
607+
Lowering::TypeConverter &TC,
608+
unsigned index);
609+
610+
inline SILType getSILBoxFieldType(SILBoxType *type,
611+
Lowering::TypeConverter &TC,
612+
unsigned index) {
613+
return SILType::getPrimitiveAddressType(
614+
getSILBoxFieldLoweredType(type, TC, index));
615+
}
616+
595617
} // end swift namespace
596618

597619
namespace llvm {

trunk/include/swift/SIL/TypeLowering.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace swift {
3535
class ForeignErrorConvention;
3636
enum IsInitialization_t : bool;
3737
enum IsTake_t : bool;
38+
class ModuleDecl;
3839
class SILBuilder;
3940
class SILLocation;
4041
class SILModule;
@@ -712,10 +713,10 @@ class TypeConverter {
712713
const TypeLowering *lowering);
713714

714715
public:
715-
SILModule &M;
716+
ModuleDecl &M;
716717
ASTContext &Context;
717718

718-
TypeConverter(SILModule &m);
719+
TypeConverter(ModuleDecl &m);
719720
~TypeConverter();
720721
TypeConverter(TypeConverter const &) = delete;
721722
TypeConverter &operator=(TypeConverter const &) = delete;
@@ -803,7 +804,8 @@ class TypeConverter {
803804
}
804805

805806
SILType getLoweredLoadableType(Type t,
806-
ResilienceExpansion forExpansion) {
807+
ResilienceExpansion forExpansion,
808+
SILModule &M) {
807809
const TypeLowering &ti = getTypeLowering(t, forExpansion);
808810
assert(
809811
(ti.isLoadable() || !SILModuleConventions(M).useLoweredAddresses()) &&

trunk/include/swift/Subsystems.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ namespace swift {
6969
class UnifiedStatsReporter;
7070
enum class SourceFileKind;
7171

72+
namespace Lowering {
73+
class TypeConverter;
74+
}
75+
7276
/// Used to optionally maintain SIL parsing context for the parser.
7377
///
7478
/// When not parsing SIL, this has no overhead.
@@ -254,11 +258,13 @@ namespace swift {
254258
/// The module must contain source files. The optimizer will assume that the
255259
/// SIL of all files in the module is present in the SILModule.
256260
std::unique_ptr<SILModule>
257-
performSILGeneration(ModuleDecl *M, SILOptions &options);
261+
performSILGeneration(ModuleDecl *M, Lowering::TypeConverter &TC,
262+
SILOptions &options);
258263

259264
/// Turn a source file into SIL IR.
260265
std::unique_ptr<SILModule>
261-
performSILGeneration(FileUnit &SF, SILOptions &options);
266+
performSILGeneration(FileUnit &SF, Lowering::TypeConverter &TC,
267+
SILOptions &options);
262268

263269
using ModuleOrSourceFile = PointerUnion<ModuleDecl *, SourceFile *>;
264270

trunk/lib/Frontend/Frontend.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,20 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
148148
return serializationOpts;
149149
}
150150

151+
Lowering::TypeConverter &CompilerInstance::getSILTypes() {
152+
if (auto *tc = TheSILTypes.get())
153+
return *tc;
154+
155+
auto *tc = new Lowering::TypeConverter(*getMainModule());
156+
TheSILTypes.reset(tc);
157+
return *tc;
158+
}
159+
151160
void CompilerInstance::createSILModule() {
152161
assert(MainModule && "main module not created yet");
153162
// Assume WMO if a -primary-file option was not provided.
154163
TheSILModule = SILModule::createEmptyModule(
155-
getMainModule(), Invocation.getSILOptions(),
164+
getMainModule(), getSILTypes(), Invocation.getSILOptions(),
156165
Invocation.getFrontendOptions().InputsAndOutputs.isWholeModule());
157166
}
158167

@@ -1071,6 +1080,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10711080

10721081
void CompilerInstance::freeASTContext() {
10731082
PersistentState.reset();
1083+
TheSILTypes.reset();
10741084
Context.reset();
10751085
MainModule = nullptr;
10761086
SML = nullptr;

0 commit comments

Comments
 (0)