-
Couldn't load subscription status.
- Fork 0
Error protocol constraint #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: typed-throws-dev
Are you sure you want to change the base?
Conversation
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.
…rror-protocol-constraint
| TheErrorType( | ||
| new (*this, AllocationArena::Permanent) | ||
| ErrorType(*this, Type(), RecursiveTypeProperties::HasError)), | ||
| TheNeverType(nullptr), |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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
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.
Last readable context: