swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.07k stars 10.33k forks source link

[SR-13095] Swift 5.1.5 compiler crashes when I try to compile code as stdlib #55541

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-13095
Radar rdar://problem/64841989
Original Reporter carlos4242 (JIRA User)
Type Bug
Environment macOS 10.15.5, compiler is Apple clang version 11.0.3 (clang-1103.0.32.62) installed as part of Xcode 11.5 swift built from source using ninja
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 8bb7c54cb2ba7b645e29341efe127ff5

Issue Description:

this code is crashing when compiled using -parse-stdlib...

@frozen
public struct SystemRandomNumberGenerator : RandomNumberGenerator {
  @inlinable
  public init() { }

  @inlinable
  public mutating func next() -> UInt32 {
    var random: UInt32 = 0
    swift_stdlib_random(&random, UInt16(MemoryLayout<UInt32>.size))
    return random
  }
}

Here's the C code being called...

SWIFT_RUNTIME_STDLIB_API void swift_stdlib_random(void *buf, __swift_size_t nbytes);

where __swift_size_t is defined as

typedef uint16_t __swift_size_t;

Seems to be a problem with the clang importer or something similar.

Here is the backtrace...

 thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = instruction step over
  * frame #&#8203;0: 0x00007fff715af344 libsystem_kernel.dylib`__pthread_kill + 20
    frame #&#8203;1: 0x00007fff7166be60 libsystem_pthread.dylib`pthread_kill + 430
    frame #&#8203;2: 0x00007fff71536808 libsystem_c.dylib`abort + 120
    frame #&#8203;3: 0x00007fff71535ac6 libsystem_c.dylib`__assert_rtn + 314
    frame #&#8203;4: 0x000000010252caf9 swift`swift::ValueDecl::getInterfaceType(this=0x0000000120087500) const at Decl.cpp:2615:3
    frame #&#8203;5: 0x00000001027fc452 swift`swift::TypeBase::getTypeOfMember(this=0x0000000120116270, module=0x0000000120849340, member=0x0000000120087500, memberType=Type @ 0x00007ffeefbefc50) at Type.cpp:3577:26
    frame #&#8203;6: 0x00000001016bbf64 swift`(anonymous namespace)::LowerType::visitAnyStructType(this=0x00007ffeefbf02e0, structType=CanType @ 0x00007ffeefbefe00, D=0x000000012084b0c8) at TypeLowering.cpp:1280:23
    frame #&#8203;7: 0x00000001016b5ac6 swift`(anonymous namespace)::TypeClassifierBase<(this=0x00007ffeefbf02e0, type=swift::CanStructType @ 0x00007ffeefbefe38)::LowerType, swift::Lowering::TypeLowering*>::visitStructType(swift::CanTypeWrapper<swift::StructType>) at TypeLowering.cpp:408:23
    frame #&#8203;8: 0x00000001016a429b swift`swift::CanTypeVisitor<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering*>::visit(this=0x00007ffeefbf02e0, T=CanType @ 0x00007ffeefbf0230) at TypeNodes.def:116:7
    frame #&#8203;9: 0x00000001016a4c9f swift`swift::Lowering::TypeConverter::getTypeLoweringForLoweredType(this=0x00000001211833c0, key=TypeKey @ 0x00007ffeefbf03c0, forExpansion=Minimal) at TypeLowering.cpp:1688:43
    frame #&#8203;10: 0x00000001016a328e swift`swift::Lowering::TypeConverter::getTypeLowering(this=0x00000001211833c0, origType=AbstractionPattern @ 0x00007ffeefbf0670, origSubstType=Type @ 0x00007ffeefbf0650, forExpansion=Minimal) at TypeLowering.cpp:1536:17
    frame #&#8203;11: 0x00000001014ad917 swift`(anonymous namespace)::DestructureInputs::visit(this=0x00007ffeefbf0ee8, ownership=Default, forSelf=false, origType=AbstractionPattern @ 0x00007ffeefbf0820, substType=CanType @ 0x00007ffeefbf0808, rep=CFunctionPointer) at SILFunctionType.cpp:590:29
    frame #&#8203;12: 0x00000001014ad2ae swift`(anonymous namespace)::DestructureInputs::visitTopLevelParams(this=0x00007ffeefbf0ee8, origType=AbstractionPattern @ 0x00007ffeefbf09e0, params=swift::CanTypeWrapper<swift::AnyFunctionType>::CanParamArrayRef @ 0x00007ffeefbf09c0, extInfo=(Bits = 3)), true>, swift::AnyFunctionType::ExtInfo) at SILFunctionType.cpp:536:7
    frame #&#8203;13: 0x00000001014abc5d swift`(anonymous namespace)::DestructureInputs::destructure(this=0x00007ffeefbf0ee8, origType=AbstractionPattern @ 0x00007ffeefbf0a70, params=swift::CanTypeWrapper<swift::AnyFunctionType>::CanParamArrayRef @ 0x00007ffeefbf0a50, extInfo=(Bits = 3)), true>, swift::AnyFunctionType::ExtInfo) at SILFunctionType.cpp:484:5
    frame #&#8203;14: 0x00000001014aa7d7 swift`getSILFunctionType(M=0x0000000121183000, origType=AbstractionPattern @ 0x00007ffeefbf0f80, substFnInterfaceType=swift::CanAnyFunctionType @ 0x00007ffeefbf0e68, extInfo=(Bits = 3), conventions=0x00007ffeefbf1038, foreignInfo=0x00007ffeefbf1430, origConstant=Optional<swift::SILDeclRef> @ 0x00007ffeefbf0fa0, constant=Optional<swift::SILDeclRef> @ 0x00007ffeefbf0fb8, reqtSubs=Optional<swift::SubstitutionMap> @ 0x00007ffeefbf0fd0, witnessMethodConformance=Optional<swift::ProtocolConformanceRef> @ 0x00007ffeefbf0fe0)::Conventions const&, swift::ForeignInfo const&, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, llvm::Optional<swift::ProtocolConformanceRef>) at SILFunctionType.cpp:990:18
    frame #&#8203;15: 0x00000001014afbb3 swift`getSILFunctionTypeForClangDecl(M=0x0000000121183000, clangDecl=0x000000012181a4e8, origType=swift::CanAnyFunctionType @ 0x00007ffeefbf1178, substInterfaceType=swift::CanAnyFunctionType @ 0x00007ffeefbf1170, extInfo=(Bits = 3), foreignInfo=0x00007ffeefbf1430, constant=Optional<swift::SILDeclRef> @ 0x00007ffeefbf1240) at SILFunctionType.cpp:1671:12
    frame #&#8203;16: 0x00000001014a4134 swift`getUncachedSILFunctionTypeForConstant(M=0x0000000121183000, constant=SILDeclRef @ 0x00007ffeefbf13c8, origLoweredInterfaceType=swift::CanAnyFunctionType @ 0x00007ffeefbf13c0) at SILFunctionType.cpp:1948:14
    frame #&#8203;17: 0x00000001014a47ef swift`swift::Lowering::TypeConverter::getConstantInfo(this=0x00000001211833c0, constant=SILDeclRef @ 0x00007ffeefbf16f8) at SILFunctionType.cpp:2070:5
    frame #&#8203;18: 0x0000000100a4957c swift`swift::Lowering::SILGenFunction::getConstantInfo(this=0x00007ffeefbf3b18, constant=SILDeclRef @ 0x00007ffeefbf1ba0) at SILGenFunction.h:528:22
    frame #&#8203;19: 0x00000001009c241a swift`(anonymous namespace)::Callee::forDirect(SGF=0x00007ffeefbf3b18, c=SILDeclRef @ 0x00007ffeefbf1cb0, subs=SubstitutionMap @ 0x00007ffeefbf1ca8, l=SILLocation @ 0x00007ffeefbf1cf0, callPreviousDynamicReplaceableImpl=false) at SILGenApply.cpp:386:20
    frame #&#8203;20: 0x00000001009de433 swift`(anonymous namespace)::SILGenApply::visitDeclRefExpr(this=0x00007ffeefbf2418, e=0x000000012013d630) at SILGenApply.cpp:1136:17
    frame #&#8203;21: 0x00000001009dd129 swift`swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visit(this=0x00007ffeefbf2418, E=0x000000012013d630) at ExprNodes.def:82:1
    frame #&#8203;22: 0x00000001009e3d42 swift`(anonymous namespace)::SILGenApply::visitApplyExpr(this=0x00007ffeefbf2418, e=0x000000012104b540) at SILGenApply.cpp:882:5
    frame #&#8203;23: 0x00000001009dee43 swift`swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visitCallExpr(this=0x00007ffeefbf2418, E=0x000000012104b540) at ExprNodes.def:135:3
    frame #&#8203;24: 0x00000001009dd527 swift`swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visit(this=0x00007ffeefbf2418, E=0x000000012104b540) at ExprNodes.def:135:3
    frame #&#8203;25: 0x00000001009dca10 swift`(anonymous namespace)::SILGenApply::decompose(this=0x00007ffeefbf2418, e=0x000000012104b540) at SILGenApply.cpp:854:5
    frame #&#8203;26: 0x00000001009c1741 swift`(anonymous namespace)::CallEmission::forApplyExpr(SGF=0x00007ffeefbf3b18, e=0x000000012104b540) at SILGenApply.cpp:4830:9
    frame #&#8203;27: 0x00000001009c166c swift`swift::Lowering::SILGenFunction::emitApplyExpr(this=0x00007ffeefbf3b18, e=0x000000012104b540, c=SGFContext @ 0x00007ffeefbf25b0) at SILGenApply.cpp:5329:27
    frame #&#8203;28: 0x0000000100aa6a92 swift`(anonymous namespace)::RValueEmitter::visitApplyExpr(this=0x00007ffeefbf3148, E=0x000000012104b540, C=SGFContext @ 0x00007ffeefbf2708) at SILGenExpr.cpp:666:14
    frame #&#8203;29: 0x0000000100a92a07 swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visitCallExpr(this=0x00007ffeefbf3148, E=0x000000012104b540, AA=SGFContext @ 0x00007ffeefbf2758) at ExprNodes.def:135:3
    frame #&#8203;30: 0x0000000100a7cbcd swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(this=0x00007ffeefbf3148, E=0x000000012104b540, AA=SGFContext @ 0x00007ffeefbf3108) at ExprNodes.def:135:3
    frame #&#8203;31: 0x0000000100a6bc84 swift`swift::Lowering::SILGenFunction::emitRValue(this=0x00007ffeefbf3b18, E=0x000000012104b540, C=SGFContext @ 0x00007ffeefbf3168) at SILGenExpr.cpp:5381:31
    frame #&#8203;32: 0x0000000100b668fe swift`swift::Lowering::SILGenFunction::emitReturnExpr(this=0x00007ffeefbf3b18, branchLoc=SILLocation @ 0x00007ffeefbf34a0, ret=0x000000012104b540) at SILGenStmt.cpp:476:17
    frame #&#8203;33: 0x0000000100b695c8 swift`(anonymous namespace)::StmtEmitter::visitReturnStmt(this=0x00007ffeefbf3858, S=0x000000012104b578) at SILGenStmt.cpp:496:9
    frame #&#8203;34: 0x0000000100b654c1 swift`swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(this=0x00007ffeefbf3858, S=0x000000012104b578) at StmtNodes.def:48:1
    frame #&#8203;35: 0x0000000100b691be swift`(anonymous namespace)::StmtEmitter::visitBraceStmt(this=0x00007ffeefbf3858, S=0x000000012104b598) at SILGenStmt.cpp:336:7
    frame #&#8203;36: 0x0000000100b654a9 swift`swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(this=0x00007ffeefbf3858, S=0x000000012104b598) at StmtNodes.def:47:1
    frame #&#8203;37: 0x0000000100b6540d swift`swift::Lowering::SILGenFunction::emitStmt(this=0x00007ffeefbf3b18, S=0x000000012104b598) at SILGenStmt.cpp:197:22
    frame #&#8203;38: 0x0000000100ac157c swift`swift::Lowering::SILGenFunction::emitClosure(this=0x00007ffeefbf3b18, ace=0x000000012104b260) at SILGenFunction.cpp:431:5
    frame #&#8203;39: 0x000000010098cce5 swift`swift::Lowering::SILGenModule::emitClosure(this=0x00007ffeefbfa898, ce=0x000000012104b260) at SILGen.cpp:933:33
    frame #&#8203;40: 0x0000000100a9ecf5 swift`(anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(this=0x00007ffeefbf4be8, e=0x000000012104b260, C=SGFContext @ 0x00007ffeefbf41a8) at SILGenExpr.cpp:2467:11
    frame #&#8203;41: 0x0000000100a90b47 swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visitClosureExpr(this=0x00007ffeefbf4be8, E=0x000000012104b260, AA=SGFContext @ 0x00007ffeefbf41f8) at ExprNodes.def:121:3
    frame #&#8203;42: 0x0000000100a7c7b4 swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(this=0x00007ffeefbf4be8, E=0x000000012104b268, AA=SGFContext @ 0x00007ffeefbf4ba8) at ExprNodes.def:121:3
    frame #&#8203;43: 0x0000000100a6bc84 swift`swift::Lowering::SILGenFunction::emitRValue(this=0x00007ffeefbf95f8, E=0x000000012104b268, C=SGFContext @ 0x00007ffeefbf4c08) at SILGenExpr.cpp:5381:31
    frame #&#8203;44: 0x0000000100a70942 swift`swift::Lowering::SILGenFunction::emitRValueAsSingleValue(this=0x00007ffeefbf95f8, E=0x000000012104b268, C=SGFContext @ 0x00007ffeefbf4ca8) at SILGenExpr.cpp:5491:10
    frame #&#8203;45: 0x0000000100a93a08 swift`(anonymous namespace)::RValueEmitter::visitFunctionConversionExpr(this=0x00007ffeefbf5ab8, e=0x00000001208fd9d8, C=SGFContext @ 0x00007ffeefbf50c8) at SILGenExpr.cpp:1692:21
    frame #&#8203;46: 0x0000000100a7cf01 swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(this=0x00007ffeefbf5ab8, E=0x00000001208fd9d8, AA=SGFContext @ 0x00007ffeefbf5a78) at ExprNodes.def:149:3
    frame #&#8203;47: 0x0000000100a6bc84 swift`swift::Lowering::SILGenFunction::emitRValue(this=0x00007ffeefbf95f8, E=0x00000001208fd9d8, C=SGFContext @ 0x00007ffeefbf5ad8) at SILGenExpr.cpp:5381:31
    frame #&#8203;48: 0x0000000100a70942 swift`swift::Lowering::SILGenFunction::emitRValueAsSingleValue(this=0x00007ffeefbf95f8, E=0x00000001208fd9d8, C=SGFContext @ 0x00007ffeefbf5b78) at SILGenExpr.cpp:5491:10
    frame #&#8203;49: 0x000000010094c340 swift`swift::Lowering::ArgumentSource::getAsSingleValue(this=0x00007ffeefbf6b40, SGF=0x00007ffeefbf95f8, C=SGFContext @ 0x00007ffeefbf5d18) && at ArgumentSource.cpp:84:18
    frame #&#8203;50: 0x0000000100950b38 swift`swift::Lowering::ArgumentSource::getConverted(this=0x00007ffeefbf60f8, SGF=0x00007ffeefbf95f8, loc=SILLocation @ 0x00007ffeefbf5d80, C=SGFContext @ 0x00007ffeefbf5d58) &&::$_0::operator()(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext) const at ArgumentSource.cpp:112:31
    frame #&#8203;51: 0x0000000100950ae2 swift`swift::Lowering::ManagedValue llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>::callback_fn<swift::Lowering::ArgumentSource::getConverted(callable=140732920717560, params=0x00007ffeefbf95f8, params=SILLocation @ 0x00007ffeefbf5e10, params=SGFContext @ 0x00007ffeefbf5de8) &&::$_0>(long, swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext) at STLExtras.h:120:12
    frame #&#8203;52: 0x0000000100a3376e swift`llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>::operator(this=0x00007ffeefbf5fc8, params=0x00007ffeefbf95f8, params=SILLocation @ 0x00007ffeefbf5ea0, params=SGFContext @ 0x00007ffeefbf5e78)(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext) const at STLExtras.h:137:12
    frame #&#8203;53: 0x0000000100a3808d swift`swift::Lowering::SILGenFunction::emitConvertedRValue(this=0x00007ffeefbf95f8, loc=SILLocation @ 0x00007ffeefbf60c0, conversion=0x00007ffeefbf6270, C=SGFContext @ 0x00007ffeefbf5fd8, produceValue=swift::Lowering::ValueProducerRef @ 0x00007ffeefbf5fc8)>) at SILGenConvert.cpp:1040:17
    frame #&#8203;54: 0x000000010094c5dd swift`swift::Lowering::ArgumentSource::getConverted(this=0x00007ffeefbf6b40, SGF=0x00007ffeefbf95f8, conversion=0x00007ffeefbf6270, C=SGFContext @ 0x00007ffeefbf6148) && at ArgumentSource.cpp:110:16
    frame #&#8203;55: 0x00000001009d6c08 swift`(anonymous namespace)::ArgEmitter::emitConvertedArgument(this=0x00007ffeefbf7470, arg=0x00007ffeefbf6b40, conversion=Conversion @ 0x00007ffeefbf6270, C=SGFContext @ 0x00007ffeefbf6248) at SILGenApply.cpp:3274:34
    frame #&#8203;56: 0x00000001009d126d swift`(anonymous namespace)::ArgEmitter::emitDirect(this=0x00007ffeefbf7470, arg=0x00007ffeefbf6b40, loweredSubstArgType=SILType @ 0x00007ffeefbf6428, origParamType=AbstractionPattern @ 0x00007ffeefbf64d0, param=SILParameterInfo @ 0x00007ffeefbf6420) at SILGenApply.cpp:3080:15
    frame #&#8203;57: 0x00000001009cfb8b swift`(anonymous namespace)::ArgEmitter::emit(this=0x00007ffeefbf7470, arg=0x00007ffeefbf6b40, origParamType=AbstractionPattern @ 0x00007ffeefbf6730) at SILGenApply.cpp:2847:5
    frame #&#8203;58: 0x00000001009d0532 swift`(anonymous namespace)::ArgEmitter::emitExpanded(this=0x00007ffeefbf7470, arg=0x000000011f93a930, origParamType=AbstractionPattern @ 0x00007ffeefbf6c30) at SILGenApply.cpp:2907:9
    frame #&#8203;59: 0x00000001009cf477 swift`(anonymous namespace)::ArgEmitter::emit(this=0x00007ffeefbf7470, arg=0x000000011f93a930, origParamType=AbstractionPattern @ 0x00007ffeefbf6e90) at SILGenApply.cpp:2770:9
    frame #&#8203;60: 0x00000001009bfb1e swift`(anonymous namespace)::ArgEmitter::emitSingleArg(this=0x00007ffeefbf7470, arg=0x000000011f93a930, origParamType=AbstractionPattern @ 0x00007ffeefbf6f00) at SILGenApply.cpp:2698:5
    frame #&#8203;61: 0x00000001009eef12 swift`(anonymous namespace)::ArgEmitter::emitTopLevel(this=0x00007ffeefbf7470, arg=0x000000011f93a930, origFormalType=AbstractionPattern @ 0x00007ffeefbf7210) at SILGenApply.cpp:2744:5
    frame #&#8203;62: 0x00000001009ee53c swift`(anonymous namespace)::ArgEmitter::emitPreparedArgs(this=0x00007ffeefbf7470, args=0x000000011f93aa20, origFormalType=AbstractionPattern @ 0x00007ffeefbf72f0) at SILGenApply.cpp:2755:7
    frame #&#8203;63: 0x00000001009ed302 swift`(anonymous namespace)::CallSite::emit(this=0x000000011f93aa00, SGF=0x00007ffeefbf95f8, origFormalType=AbstractionPattern @ 0x00007ffeefbf7520, substFnType=swift::CanSILFunctionType @ 0x00007ffeefbf7450, lowering=0x00007ffeefbf7868, args=0x00007ffeefbf7a30, delayedArgs=0x00007ffeefbf78d0, foreignError=0x00007ffeefbf7b60, foreignSelf=(rawValue = '\0'))::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && at SILGenApply.cpp:4085:13
    frame #&#8203;64: 0x00000001009ec0fb swift`(anonymous namespace)::CallEmission::emitArgumentsForNormalApply(this=0x00007ffeefbf81a8, formalType=0x00007ffeefbf8140, origFormalType=0x00007ffeefbf7e30, substFnType=swift::CanSILFunctionType @ 0x00007ffeefbf7b00, foreignError=0x00007ffeefbf7f70, foreignSelf=(rawValue = '\0'), uncurriedArgs=0x00007ffeefbf7d20, uncurriedLoc=0x00007ffeefbf7ea8, formalApplyType=0x00007ffeefbf7d18) at SILGenApply.cpp:4726:23
    frame #&#8203;65: 0x00000001009eb4bd swift`(anonymous namespace)::CallEmission::applyNormalCall(this=0x00007ffeefbf81a8, C=SGFContext @ 0x00007ffeefbf7e70) at SILGenApply.cpp:4455:26
    frame #&#8203;66: 0x00000001009e8550 swift`(anonymous namespace)::CallEmission::applyFirstLevelCallee(this=0x00007ffeefbf81a8, C=SGFContext @ 0x00007ffeefbf8018) at SILGenApply.cpp:4407:10
    frame #&#8203;67: 0x00000001009c1a2d swift`(anonymous namespace)::CallEmission::apply(this=0x00007ffeefbf81a8, C=SGFContext @ 0x00007ffeefbf8158) at SILGenApply.cpp:4174:29
    frame #&#8203;68: 0x00000001009c1694 swift`swift::Lowering::SILGenFunction::emitApplyExpr(this=0x00007ffeefbf95f8, e=0x000000012104b618, c=SGFContext @ 0x00007ffeefbf81a0) at SILGenApply.cpp:5330:19
    frame #&#8203;69: 0x0000000100aa6a92 swift`(anonymous namespace)::RValueEmitter::visitApplyExpr(this=0x00007ffeefbf8d38, E=0x000000012104b618, C=SGFContext @ 0x00007ffeefbf82f8) at SILGenExpr.cpp:666:14
    frame #&#8203;70: 0x0000000100a92a07 swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visitCallExpr(this=0x00007ffeefbf8d38, E=0x000000012104b618, AA=SGFContext @ 0x00007ffeefbf8348) at ExprNodes.def:135:3
    frame #&#8203;71: 0x0000000100a7cbcd swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(this=0x00007ffeefbf8d38, E=0x000000012104b618, AA=SGFContext @ 0x00007ffeefbf8cf8) at ExprNodes.def:135:3
    frame #&#8203;72: 0x0000000100a6bc84 swift`swift::Lowering::SILGenFunction::emitRValue(this=0x00007ffeefbf95f8, E=0x000000012104b618, C=SGFContext @ 0x00007ffeefbf8d58) at SILGenExpr.cpp:5381:31
    frame #&#8203;73: 0x0000000100a71765 swift`swift::Lowering::SILGenFunction::emitIgnoredExpr(this=0x00007ffeefbf95f8, E=0x000000012104b618) at SILGenExpr.cpp:5485:3
    frame #&#8203;74: 0x0000000100b6927d swift`(anonymous namespace)::StmtEmitter::visitBraceStmt(this=0x00007ffeefbf93d8, S=0x000000012104b6b8) at SILGenStmt.cpp:346:11
    frame #&#8203;75: 0x0000000100b654a9 swift`swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(this=0x00007ffeefbf93d8, S=0x000000012104b6b8) at StmtNodes.def:47:1
    frame #&#8203;76: 0x0000000100b6540d swift`swift::Lowering::SILGenFunction::emitStmt(this=0x00007ffeefbf95f8, S=0x000000012104b6b8) at SILGenStmt.cpp:197:22
    frame #&#8203;77: 0x0000000100ac0baf swift`swift::Lowering::SILGenFunction::emitFunction(this=0x00007ffeefbf95f8, fd=0x000000012104adb0) at SILGenFunction.cpp:414:3
    frame #&#8203;78: 0x00000001009a6f36 swift`swift::Lowering::SILGenModule::emitFunction(this=0x00007ffeefbf9d58, f=0x000000012118ecf0)::$_0::operator()(swift::SILFunction*) const at SILGen.cpp:826:37
    frame #&#8203;79: 0x000000010098b91f swift`void emitOrDelayFunction<swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_0>(SGM=0x00007ffeefbfa898, constant=SILDeclRef @ 0x00007ffeefbf9c30, emitter=0x00007ffeefbf9d58, forceEmission=false)::$_0&&, bool) at SILGen.cpp:718:3
    frame #&#8203;80: 0x000000010098a2a2 swift`swift::Lowering::SILGenModule::emitFunction(this=0x00007ffeefbfa898, fd=0x000000012104adb0) at SILGen.cpp:823:5
    frame #&#8203;81: 0x0000000100b86cf4 swift`(anonymous namespace)::SILGenType::visitFuncDecl(this=0x00007ffeefbfa280, fd=0x000000012104adb0) at SILGenType.cpp:1011:9
    frame #&#8203;82: 0x0000000100b85fbc swift`swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(this=0x00007ffeefbfa280, D=0x000000012104add0) at DeclNodes.def:172:5
    frame #&#8203;83: 0x0000000100b7dc41 swift`(anonymous namespace)::SILGenType::emitType(this=0x00007ffeefbfa280) at SILGenType.cpp:967:7
    frame #&#8203;84: 0x0000000100b7db6a swift`swift::Lowering::SILGenModule::visitNominalTypeDecl(this=0x00007ffeefbfa898, ntd=0x000000012104aa00) at SILGenType.cpp:1072:26
    frame #&#8203;85: 0x00000001009ba863 swift`swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visitStructDecl(this=0x00007ffeefbfa898, D=0x000000012104aa00) at DeclNodes.def:151:9
    frame #&#8203;86: 0x0000000100993a22 swift`swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(this=0x00007ffeefbfa898, D=0x000000012104aa20) at DeclNodes.def:151:9
    frame #&#8203;87: 0x0000000100993582 swift`swift::Lowering::SILGenModule::emitSourceFile(this=0x00007ffeefbfa898, sf=0x0000000121044600) at SILGen.cpp:1730:5
    frame #&#8203;88: 0x000000010099448d swift`swift::SILModule::constructSIL(mod=0x0000000120849340, options=0x00007ffeefbfc508, SF=0x0000000121044600) at SILGen.cpp:1763:11
    frame #&#8203;89: 0x0000000100994e4b swift`swift::performSILGeneration(sf=0x0000000121044600, options=0x00007ffeefbfc508) at SILGen.cpp:1821:10
    frame #&#8203;90: 0x0000000100127436 swift`generateSILModules(Invocation=0x00007ffeefbfbeb8, Instance=0x0000000120025c00) at FrontendTool.cpp:880:15
    frame #&#8203;91: 0x000000010011d41b swift`performCompile(Instance=0x0000000120025c00, Invocation=0x00007ffeefbfbeb8, Args=ArrayRef<const char *> @ 0x00007ffeefbfba70, ReturnValue=0x00007ffeefbfbbec, observer=0x0000000000000000, Stats=0x0000000000000000) at FrontendTool.cpp:1074:40
    frame #&#8203;92: 0x000000010011bfc1 swift`swift::performFrontend(Args=ArrayRef<const char *> @ 0x00007ffeefbfbe28, Argv0="/Users/carlpeto/avr-swift/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift", MainAddr=0x0000000100002400, observer=0x0000000000000000) at FrontendTool.cpp:1819:5
    frame #&#8203;93: 0x00000001000045b5 swift`run_driver(ExecName=(Data = "swift", Length = 5), argv=const llvm::ArrayRef<const char *> @ 0x00007ffeefbfcca0) at driver.cpp:125:14
    frame #&#8203;94: 0x0000000100002ed4 swift`main(argc_=59, argv_=0x00007ffeefbff338) at driver.cpp:270:12
    frame #&#8203;95: 0x00007fff71467cc9 libdyld.dylib`start + 1
    frame #&#8203;96: 0x00007fff71467cc9 libdyld.dylib`start + 1
getInterfaceType()

is trapping because

hasInterfaceType()

is false.

The struct being lowered seems to be UnsafeMutableRawPointer and the field being lowered seems to be _rawValue.

my standard library project has the basics, Unsafe pointers, integer types, optional, collections, sequence, iterator but not arrays or strings.

typesanitizer commented 4 years ago

Could you please:

  1. Provide exact reproduction steps (you've noted the configuration, that's a good start). Ideally, we'd have your stdlib at a particular commit which can be checked out and known to trigger this issue. If you use create a branch for it (say sr-13095), please note down the HEAD commit hash as well in case someone (force) pushes to it.

  2. Format the code in the description using Jira markup? The description is difficult to read without proper formatting.

swift-ci commented 4 years ago

Comment by Carl Peto (JIRA)

yes, sorry, I've reformatted the code accordingly

it's hard to extract the stdlib in a concise way, it's inside a project in a private repository, is there a channel for sharing protected code?

This is a completely separate project from the standard library inside swift/stdlib but as i understand it should be generally supported to do this sort of thing. 😉

swift-ci commented 4 years ago

Comment by Carl Peto (JIRA)

another approach on this, rather than trying to reproduce the bug elsewhere... i can look at various reasons why it's like this... I'd enjoy a bit more background on what's going on here.

The code seems to be trying to emit a SIL function, but is unable to lower the code to SIL because something isn't loaded.

1) what does getInterfaceType() retrieve? Is it loading some kind of cached information about the type of a valueDecl in the AST? In this case, the type being referenced is UnsafeMutableRawPointer and the field in question is _rawValue.

For reference the UnsafeMutableRawPointer code is like this (extracted for clarity)...

@frozen
public struct UnsafeMutableRawPointer: _Pointer {

 public typealias Pointee = UInt8

 public let _rawValue: Builtin.RawPointer
 @_transparent
 public init(_ _rawValue: Builtin.RawPointer) {
   self._rawValue = _rawValue
 }

...I would assume❓ that by the time SIL is being emitted, semantic analysis is complete and the code for UnsafeMutableRawPointer has been read and parsed, so i don't understand why the AST hasn't already got the type for this field as Builtin.RawPointer?

2) I've heard the terms declared type and canonical type in this area. I don't really know what they mean or if they are relevant here? Is there any documentation on this?

By the way, this bug comes out of a lab session. I spoke to Pavel this morning about this issue and he agreed it looked like a bug and asked me to raise a ticket on here because we ran out of time in our call to fix it there.

typesanitizer commented 4 years ago

Thanks for formatting the code.

it's hard to extract the stdlib in a concise way, it's inside a project in a private repository, is there a channel for sharing protected code?

Yes, you can file a feedback using feedbackassistant.apple.com. Many people use it and attach code examples/projects that they cannot make public.

This is a completely separate project from the standard library inside swift/stdlib but as i understand it should be generally supported to do this sort of thing.

Well, I'm going to have to disagree since you are using the -parse-stdlib flag. 😛 We don't expect most (99.99%+) people to be using that flag.

what does getInterfaceType() retrieve? Is it loading some kind of cached information about the type of a valueDecl in the AST?

There is a short description in docs/Lexicon.md.

interface type

The type of a value or declaration outside its generic context. These types are written using "formal" generic types, which only have meaning when combined with a particular generic declaration's "generic signature". Unlike contextual types, interface types store conformances and requirements in the generic signature and not in the types themselves. They can be compared across declarations but cannot be used directly from within the context.

You might also want to see other descriptions in that file.

I've heard the terms declared type and canonical type in this area. I don't really know what they mean or if they are relevant here? Is there any documentation on this?

I don't know about declared type but canonical type is not relevant afaict. The doc comments are a bit sparse but docs/Lexicon.md and Slava's article https://medium.com/@slavapestov/the-secret-life-of-types-in-swift-ff83c3c000a5 would be good places to start. You might also want to check out docs/README.md which describes how the documentation is organized; it might help you find other relevant information.

By the way, this bug comes out of a lab session. I spoke to Pavel this morning about this issue and he agreed it looked like a bug and asked me to raise a ticket on here because we ran out of time in our call to fix it there.

I'm not saying it's not a bug. The compiler is crashing, and the compiler should not crash. So it's certainly a bug. All I'm saying is that providing more information would help in understanding things better. It's much easier to understand what's going on if the issue can be reproduced/debugged compared to just looking at the trace and the surrounding code. Moreover, reproduction information is valuable in case someone else encounters a similar issue; then they can compare/contrast what you were doing to what they are doing.

typesanitizer commented 4 years ago

Also, please leave a comment here with the feedback number in case you decide to file a feedback so we can connect the feedback to this JIRA.

swift-ci commented 4 years ago

Comment by Carl Peto (JIRA)

I've submitted code and build instructions to the apple feedback assistant with reference FB7805790.

p.s. thanks so much for all your help, obviously making stdlib is a very rare thing to do, all I meant is that from my conversations with some developers they've suggested that even when compiling stdlib, the compiler shouldn't crash. That's all I meant! 🙂

Carl