Skip to content

Conversation

@minuscorp
Copy link
Owner

@minuscorp minuscorp commented Sep 7, 2020

This PR adds the Error protocol constraint to throwing types but fails in (among other things surely) serialize variables that come from protocols that bridge from ObjC variables it seems (like Error protocol) other protocols seems to work ok, both own ones like CustomStringConvertible or anyone from Foundation or another modules that can be imported. I can't. trace more the error but not the root of itself.

frame #3: 0x0000000101a44d4e swift-frontend`swift::ModuleFileSharedCore::fatal(error=<unavailable>) at ModuleFileSharedCore.cpp:453:3
    frame #4: 0x000000010193cf82 swift-frontend`swift::ModuleFile::fatal(this=0x000000012c00fa00, error=<unavailable>) at Deserialization.cpp:192:3
    frame #5: 0x000000010193d329 swift-frontend`swift::ModuleFile::getDecl(this=0x000000012c00fa00, DID=(Value = 2353642078208)) at Deserialization.cpp:2327:5
    frame #6: 0x0000000101949fe3 swift-frontend`swift::ModuleFile::configureStorage(this=0x000000012c00fa00, decl=0x0000000134864388, rawOpaqueReadOwnership='\0', rawReadImplKind='\x01', rawWriteImplKind='\0', rawReadWriteImplKind='\0', rawIDs=0x00007ffeefbf7690) at Deserialization.cpp:2251:52
    frame #7: 0x00000001019557cf swift-frontend`swift::DeclDeserializer::deserializeVar(this=0x00007ffeefbf7f10, scratch=ArrayRef<unsigned long long> @ 0x00007ffeefbf7740, blobData=(Data = 0x0000000000000000, Length = 0)) at Deserialization.cpp:2847:8
    frame #8: 0x000000010194ae36 swift-frontend`swift::DeclDeserializer::getDeclCheckedImpl(this=0x00007ffeefbf7f10, matchAttributes=function_ref<bool (swift::DeclAttributes)> @ 0x00007ffeefbf7e30)>) at Deserialization.cpp:4565:3
    frame #9: 0x000000010193e56a swift-frontend`swift::ModuleFile::getDeclChecked(this=0x000000012c00fa00, DID=(Value = 48704929136640), matchAttributes=function_ref<bool (swift::DeclAttributes)> @ 0x00007ffeefbf7fb0)>) at Deserialization.cpp:4051:45
    frame #10: 0x000000010193da45 swift-frontend`swift::ModuleFile::readPattern(this=0x000000012c00fa00, owningDC=0x0000000134863fc8) at Deserialization.cpp:354:25
    frame #11: 0x000000010193dc4c swift-frontend`swift::ModuleFile::readPattern(this=0x000000012c00fa00, owningDC=0x0000000134863fc8) at Deserialization.cpp:380:38
    frame #12: 0x0000000101956ca4 swift-frontend`swift::DeclDeserializer::deserializePatternBinding(this=0x00007ffeefbf9160, scratch=ArrayRef<unsigned long long> @ 0x00007ffeefbf89c0, blobData=(Data = 0x0000000000000000, Length = 0)) at Deserialization.cpp:3315:25
    frame #13: 0x000000010194b25f swift-frontend`swift::DeclDeserializer::getDeclCheckedImpl(this=0x00007ffeefbf9160, matchAttributes=function_ref<bool (swift::DeclAttributes)> @ 0x00007ffeefbf9080)>) at Deserialization.cpp:4570:3
    frame #14: 0x000000010193e56a swift-frontend`swift::ModuleFile::getDeclChecked(this=0x000000012c00fa00, DID=(Value = 48765058678784), matchAttributes=function_ref<bool (swift::DeclAttributes)> @ 0x00007ffeefbf9200)>) at Deserialization.cpp:4051:45
    frame #15: 0x000000010196156b swift-frontend`swift::ModuleFile::loadAllMembers(this=0x000000012c00fa00, container=0x0000000134863fd0, contextData=56099726) at Deserialization.cpp:5946:29

Last readable context:

(var_decl "_domain" type='String' interface type='String' readImpl=getter writeImpl=setter readWriteImpl=modify_coroutine)
2.	While evaluating request TypeCheckSourceFileRequest(source_file "/Users/minuscorp/Documents/swift-source/swift/test/Parse/errors.swift")
3.	While type-checking 'SomeError' (at /Users/minuscorp/Documents/swift-source/swift/test/Parse/errors.swift:3:1)
4.	While type-checking protocol conformance to 'Error' (in module 'Swift') for type 'SomeError' (declared at [/Users/minuscorp/Documents/swift-source/swift/test/Parse/errors.swift:3:1 - line:3:26] RangeText="struct SomeError: Error {")
5.	While loading members for 'Error' (in module 'Swift')
6.	While deserializing decl @ 58232271 (PATTERN_BINDING_DECL) in 'Swift'
7.	While deserializing '_domain' (VarDecl @ 58230816) in 'Swift'
8.	    ...decl is named '_domain'

Zollerboy1 and others added 8 commits September 1, 2020 00:20
This doesn't currently work. I don't know at the moment, how to
constrain the throws type to Swift.Error properly
This commit is quite big, because the constructor of AnyThrowsType and
of its subclasses is used extremely much throughout the whole codebase.
Although it technically compiles, it is not building the stdlib, as I'm
getting lots of these failed assertions:

Assertion failed: (repr && "Cannot validate null TypeReprs!")
in function resolveType at lib/Sema/TypeCheckType.cpp:1872.

I suspect, that these errors are coming from a mistake, I made in the
serialization or deserialization of function types and/or declarations.
@minuscorp minuscorp requested a review from Zollerboy1 September 7, 2020 15:35
@minuscorp minuscorp marked this pull request as draft September 7, 2020 15:36
TheErrorType(
new (*this, AllocationArena::Permanent)
ErrorType(*this, Type(), RecursiveTypeProperties::HasError)),
TheNeverType(nullptr),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no way to use getNeverType here, is always null

lib/AST/Type.cpp Outdated
SmallVector<AnyFunctionType::Param, 8> canParams;
getCanonicalParams(funcTy, genericSig, canParams);
auto resultTy = funcTy->getResult()->getCanonicalType(genericSig);
auto throwsTy = funcTy->getThrowsType()->getCanonicalType(genericSig);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails always in tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot get the canonical type from a null Type. Try:

CanType throwsTy;
if (auto funcThrowsTy = funcTy->getThrowsType())
  throwsTy = funcThrowsTy->getCanonicalType(genericSig);

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with all these traces, is Never not usable to be injected as a default throwsType, even if the function doesn't throw:

swift-frontend           0x00000001039995ac swift::DeclContext::getAsDecl() + 28
6  swift-frontend           0x00000001039ebbd5 swift::DeclContext::getAsDecl() const + 21
7  swift-frontend           0x0000000103c751d5 swift::DeclContext::isModuleContext() const + 21
8  swift-frontend           0x0000000103d8d3dd swift::DeclContext::getParentModule() const + 29
9  swift-frontend           0x0000000103d8d3a5 swift::DeclContext::getASTContext() const + 21
10 swift-frontend           0x000000010397bfae swift::Decl::getASTContext() const + 62
11 swift-frontend           0x0000000103c55f34 computeNominalType(swift::NominalTypeDecl*, DeclTypeKind) + 36
12 swift-frontend           0x0000000103c5576d swift::NominalTypeDecl::getDeclaredInterfaceType() const + 93
13 swift-frontend           0x00000001039755bf swift::ASTContext::getNeverType() const + 63

  Swift(macosx-x86_64) :: IRGen/access_type_metadata_by_mangled_name.swift
  Swift(macosx-x86_64) :: IRGen/access_type_metadata_by_mangled_name_51.swift
  Swift(macosx-x86_64) :: IRGen/dllimport.swift
  Swift(macosx-x86_64) :: IRGen/enum_value_semantics_special_cases.sil
  Swift(macosx-x86_64) :: IRGen/fixlifetime.sil
  Swift(macosx-x86_64) :: IRGen/generic_metatypes.swift
  Swift(macosx-x86_64) :: IRGen/generic_metatypes_future.swift
  Swift(macosx-x86_64) :: IRGen/partial_apply_forwarder.sil
  Swift(macosx-x86_64) :: IRGen/preserve_exclusivity.swift
  Swift(macosx-x86_64) :: IRGen/prespecialized-metadata/class-inmodule-0argument-within-class-1argument-1distinct_use.swift
  Swift(macosx-x86_64) :: IRGen/sil_witness_methods.sil
  Swift(macosx-x86_64) :: IRGen/sil_witness_tables_external_witnesstable.swift
  Swift(macosx-x86_64) :: IRGen/swift3-metadata-coff.swift
  Swift(macosx-x86_64) :: IRGen/witness_method.sil
  Swift(macosx-x86_64) :: ModuleInterface/default-prebuilt-module-location-sdk-versioned.swift
  Swift(macosx-x86_64) :: ModuleInterface/default-prebuilt-module-location.swift
  Swift(macosx-x86_64) :: SIL/Parser/projection_lowered_type_parse.sil
  Swift(macosx-x86_64) :: SIL/Parser/witness_method.sil
  Swift(macosx-x86_64) :: SIL/Parser/witness_specialize.sil
  Swift(macosx-x86_64) :: SIL/Parser/witness_tables.sil
  Swift(macosx-x86_64) :: SIL/Serialization/init_existential_inst_deserializes_witness_tables.swift
  Swift(macosx-x86_64) :: SIL/Serialization/projection_lowered_type_parse.sil
  Swift(macosx-x86_64) :: SIL/Serialization/shared_function_serialization.sil
  Swift(macosx-x86_64) :: SIL/Serialization/specializer_can_deserialize.swift
  Swift(macosx-x86_64) :: SIL/Serialization/vtable.sil
  Swift(macosx-x86_64) :: SIL/Serialization/witness_tables.sil
  Swift(macosx-x86_64) :: SIL/ownership-verifier/over_consume.sil
  Swift(macosx-x86_64) :: SILGen/address_only_types.swift
  Swift(macosx-x86_64) :: SILGen/addressors.swift
  Swift(macosx-x86_64) :: SILGen/auto_closures.swift
  Swift(macosx-x86_64) :: SILGen/auto_closures_swift4.swift
  Swift(macosx-x86_64) :: SILGen/capture_typealias.swift
  Swift(macosx-x86_64) :: SILGen/class_bound_protocols.swift
  Swift(macosx-x86_64) :: SILGen/existential_metatypes.swift
  Swift(macosx-x86_64) :: SILGen/guaranteed_normal_args.swift
  Swift(macosx-x86_64) :: SILGen/guaranteed_normal_args_curry_thunks.swift
  Swift(macosx-x86_64) :: SILGen/metatype_abstraction.swift
  Swift(macosx-x86_64) :: SILGen/minimum_foreach.swift
  Swift(macosx-x86_64) :: SILGen/opaque_ownership.swift
  Swift(macosx-x86_64) :: SILGen/opaque_values_silgen_lib.swift
  Swift(macosx-x86_64) :: SILGen/ownership.swift
  Swift(macosx-x86_64) :: SILGen/polymorphic_builtins.swift
  Swift(macosx-x86_64) :: SILGen/switch_abstraction.swift
  Swift(macosx-x86_64) :: SILGen/unmanaged_ownership.swift
  Swift(macosx-x86_64) :: SILOptimizer/basic-callee-printer.sil
  Swift(macosx-x86_64) :: SILOptimizer/basic-instruction-properties.sil
  Swift(macosx-x86_64) :: SILOptimizer/capture_promotion.sil
  Swift(macosx-x86_64) :: SILOptimizer/capture_promotion_generic_context.sil
  Swift(macosx-x86_64) :: SILOptimizer/capture_promotion_generic_context_ownership.sil
  Swift(macosx-x86_64) :: SILOptimizer/capture_promotion_ownership.sil
  Swift(macosx-x86_64) :: SILOptimizer/constant_propagation_stdlib.swift
  Swift(macosx-x86_64) :: SILOptimizer/dead_witness_module.swift
  Swift(macosx-x86_64) :: SILOptimizer/devirt_class_witness_method.sil
  Swift(macosx-x86_64) :: SILOptimizer/function_order.sil
  Swift(macosx-x86_64) :: SILOptimizer/inline_devirtualize_specialize.sil
  Swift(macosx-x86_64) :: SILOptimizer/linker.swift
  Swift(macosx-x86_64) :: SILOptimizer/mandatory_combiner.sil
  Swift(macosx-x86_64) :: SILOptimizer/prespecialize.swift
  Swift(macosx-x86_64) :: SILOptimizer/semantic-arc-opts.sil
  Swift(macosx-x86_64) :: SILOptimizer/sil_witness_tables_external_witnesstable.swift
  Swift(macosx-x86_64) :: SILOptimizer/specialize_cg_update_crash.sil
  Swift(macosx-x86_64) :: Sema/stdlib_sugar_types.swift
  Swift(macosx-x86_64) :: Serialization/duplicate_normalprotocolconformance.swift
  Swift(macosx-x86_64) :: Serialization/early-serialization.swift
  Swift(macosx-x86_64) :: Serialization/vtable-function-deserialization.swift
  Swift(macosx-x86_64) :: Serialization/witnesstable-function-deserialization.swift
  Swift(macosx-x86_64) :: sil-nm/basic.sil


Testing Time: 3964.15s
  Unsupported      :  173
  Passed           : 6610
  Expectedly Failed:   23
  Failed           :   67

4 warning(s) in tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants