From 0162b8ea272e8cc6cdc127d7b18abdf57db47517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 27 Oct 2023 17:00:37 +0200 Subject: [PATCH] Remove TypeInference::unifyGeneralized() --- .../experimental/analysis/TypeInference.cpp | 13 +- .../experimental/analysis/TypeInference.h | 4 +- .../builtin/builtin_type_definition.sol | 4 +- .../inference/polymorphic_function_call.sol | 12 +- .../inference/polymorphic_type.sol | 28 ++--- .../polymorphic_type_abs_and_rep.sol | 24 ++-- ...rphic_type_instantiation_and_operators.sol | 118 +++++++++--------- 7 files changed, 97 insertions(+), 106 deletions(-) diff --git a/libsolidity/experimental/analysis/TypeInference.cpp b/libsolidity/experimental/analysis/TypeInference.cpp index 333912f02f86..3a3ebfa63a05 100644 --- a/libsolidity/experimental/analysis/TypeInference.cpp +++ b/libsolidity/experimental/analysis/TypeInference.cpp @@ -1071,18 +1071,9 @@ TypeRegistration::TypeClassInstantiations const& typeClassInstantiations(Analysi } } -void TypeInference::unifyGeneralized(Type _type, Type _scheme, std::vector _monomorphicTypes, langutil::SourceLocation _location) +experimental::Type TypeInference::polymorphicInstance(Type const& _scheme) { - solUnimplementedAssert(_monomorphicTypes.empty(), "unsupported"); - Type fresh = m_env->fresh(_scheme); - unify(_type, fresh, _location); -} - -experimental::Type TypeInference::polymorphicInstance(Type _scheme, langutil::SourceLocation _location) -{ - Type result = m_typeSystem.freshTypeVariable({}); - unifyGeneralized(result, _scheme, {}, _location); - return result; + return m_env->fresh(_scheme); } void TypeInference::unify(Type _a, Type _b, langutil::SourceLocation _location) diff --git a/libsolidity/experimental/analysis/TypeInference.h b/libsolidity/experimental/analysis/TypeInference.h index eb1b03f6974d..2f156eae02bd 100644 --- a/libsolidity/experimental/analysis/TypeInference.h +++ b/libsolidity/experimental/analysis/TypeInference.h @@ -110,8 +110,8 @@ class TypeInference: public ASTConstVisitor GlobalAnnotation& annotation(); void unify(Type _a, Type _b, langutil::SourceLocation _location = {}); - void unifyGeneralized(Type _type, Type _scheme, std::vector _monomorphicTypes, langutil::SourceLocation _location = {}); - Type polymorphicInstance(Type _scheme, langutil::SourceLocation _location = {}); + /// Creates a polymorphic instance of a global type scheme + Type polymorphicInstance(Type const& _scheme); Type memberType(Type _type, std::string _memberName, langutil::SourceLocation _location = {}); enum class ExpressionContext { Term, Type, Sort }; Type handleIdentifierByReferencedDeclaration(langutil::SourceLocation _location, Declaration const& _declaration); diff --git a/test/libsolidity/syntaxTests/experimental/builtin/builtin_type_definition.sol b/test/libsolidity/syntaxTests/experimental/builtin/builtin_type_definition.sol index d3a6ce2e5865..fc4783ceba19 100644 --- a/test/libsolidity/syntaxTests/experimental/builtin/builtin_type_definition.sol +++ b/test/libsolidity/syntaxTests/experimental/builtin/builtin_type_definition.sol @@ -84,9 +84,9 @@ contract C { // Info 4164: (525-529): Inferred type: word // Info 4164: (540-553): Inferred type: bool // Info 4164: (540-550): Inferred type: (bool, word) -> bool -// Info 4164: (540-544): Inferred type: ('cb:type, 'cc:type) +// Info 4164: (540-544): Inferred type: ('bl:type, 'bm:type) // Info 4164: (551-552): Inferred type: (bool, word) // Info 4164: (563-577): Inferred type: word // Info 4164: (563-574): Inferred type: (bool, word) -> word -// Info 4164: (563-567): Inferred type: ('ci:type, 'cj:type) +// Info 4164: (563-567): Inferred type: ('bq:type, 'br:type) // Info 4164: (575-576): Inferred type: (bool, word) diff --git a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_function_call.sol b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_function_call.sol index 6fe19f07d00e..eacc895202f3 100644 --- a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_function_call.sol +++ b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_function_call.sol @@ -18,15 +18,15 @@ function run(a: T, b: U(T), c: U(U(T))) { // Info 4164: (39-49): Inferred type: tfun('u:type, U('u:type)) // Info 4164: (45-48): Inferred type: 't:type // Info 4164: (46-47): Inferred type: 't:type -// Info 4164: (51-82): Inferred type: ('x:type, 'y:type, U('bb:type)) -> () -// Info 4164: (61-79): Inferred type: ('x:type, 'y:type, U('bb:type)) +// Info 4164: (51-82): Inferred type: ('x:type, 'y:type, U('ba:type)) -> () +// Info 4164: (61-79): Inferred type: ('x:type, 'y:type, U('ba:type)) // Info 4164: (62-63): Inferred type: 'x:type // Info 4164: (65-69): Inferred type: 'y:type // Info 4164: (68-69): Inferred type: 'y:type -// Info 4164: (71-78): Inferred type: U('bb:type) -// Info 4164: (74-78): Inferred type: U('bb:type) -// Info 4164: (74-75): Inferred type: tfun('bb:type, U('bb:type)) -// Info 4164: (76-77): Inferred type: 'bb:type +// Info 4164: (71-78): Inferred type: U('ba:type) +// Info 4164: (74-78): Inferred type: U('ba:type) +// Info 4164: (74-75): Inferred type: tfun('ba:type, U('ba:type)) +// Info 4164: (76-77): Inferred type: 'ba:type // Info 4164: (84-159): Inferred type: (T, U(T), U(U(T))) -> () // Info 4164: (96-123): Inferred type: (T, U(T), U(U(T))) // Info 4164: (97-101): Inferred type: T diff --git a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type.sol b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type.sol index eae572a0db28..b597a5b25295 100644 --- a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type.sol +++ b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type.sol @@ -29,19 +29,19 @@ function run() { // Info 4164: (88-92): Inferred type: 'bg:(type, D) // Info 4164: (100-170): Inferred type: () -> () // Info 4164: (112-114): Inferred type: () -// Info 4164: (125-141): Inferred type: T(U, 'bo:type, 'bq:(type, C)) -// Info 4164: (128-141): Inferred type: T(U, 'bo:type, 'bq:(type, C)) -// Info 4164: (128-129): Inferred type: tfun((U, 'bo:type, 'bq:(type, C)), T(U, 'bo:type, 'bq:(type, C))) +// Info 4164: (125-141): Inferred type: T(U, 'bm:type, 'bo:(type, C)) +// Info 4164: (128-141): Inferred type: T(U, 'bm:type, 'bo:(type, C)) +// Info 4164: (128-129): Inferred type: tfun((U, 'bm:type, 'bo:(type, C)), T(U, 'bm:type, 'bo:(type, C))) // Info 4164: (130-131): Inferred type: U -// Info 4164: (133-134): Inferred type: 'bo:type -// Info 4164: (136-140): Inferred type: 'bq:(type, C) -// Info 4164: (136-137): Inferred type: 'bq:(type, C) -// Info 4164: (139-140): Inferred type: 'bq:(type, C) -// Info 4164: (151-167): Inferred type: T(V, 'bx:type, 'bz:(type, D)) -// Info 4164: (154-167): Inferred type: T(V, 'bx:type, 'bz:(type, D)) -// Info 4164: (154-155): Inferred type: tfun((V, 'bx:type, 'bz:(type, D)), T(V, 'bx:type, 'bz:(type, D))) +// Info 4164: (133-134): Inferred type: 'bm:type +// Info 4164: (136-140): Inferred type: 'bo:(type, C) +// Info 4164: (136-137): Inferred type: 'bo:(type, C) +// Info 4164: (139-140): Inferred type: 'bo:(type, C) +// Info 4164: (151-167): Inferred type: T(V, 'bt:type, 'bv:(type, D)) +// Info 4164: (154-167): Inferred type: T(V, 'bt:type, 'bv:(type, D)) +// Info 4164: (154-155): Inferred type: tfun((V, 'bt:type, 'bv:(type, D)), T(V, 'bt:type, 'bv:(type, D))) // Info 4164: (156-157): Inferred type: V -// Info 4164: (159-160): Inferred type: 'bx:type -// Info 4164: (162-166): Inferred type: 'bz:(type, D) -// Info 4164: (162-163): Inferred type: 'bz:(type, D) -// Info 4164: (165-166): Inferred type: 'bz:(type, D) +// Info 4164: (159-160): Inferred type: 'bt:type +// Info 4164: (162-166): Inferred type: 'bv:(type, D) +// Info 4164: (162-163): Inferred type: 'bv:(type, D) +// Info 4164: (165-166): Inferred type: 'bv:(type, D) diff --git a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_abs_and_rep.sol b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_abs_and_rep.sol index 3c4adb71717c..89f3f5f1a8b9 100644 --- a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_abs_and_rep.sol +++ b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_abs_and_rep.sol @@ -43,13 +43,13 @@ function fun() { // Info 4164: (134-141): Inferred type: T(uint) // Info 4164: (134-135): Inferred type: tfun(uint, T(uint)) // Info 4164: (136-140): Inferred type: uint -// Info 4164: (147-155): Inferred type: T('bp:type) -// Info 4164: (147-152): Inferred type: U(uint) -> T('bp:type) -// Info 4164: (147-148): Inferred type: U('bm:type) +// Info 4164: (147-155): Inferred type: T('bi:type) +// Info 4164: (147-152): Inferred type: U(uint) -> T('bi:type) +// Info 4164: (147-148): Inferred type: U('bg:type) // Info 4164: (153-154): Inferred type: U(uint) -// Info 4164: (161-169): Inferred type: U('bv:type) -// Info 4164: (161-166): Inferred type: T(uint) -> U('bv:type) -// Info 4164: (161-162): Inferred type: U('bs:type) +// Info 4164: (161-169): Inferred type: U('bm:type) +// Info 4164: (161-166): Inferred type: T(uint) -> U('bm:type) +// Info 4164: (161-162): Inferred type: U('bk:type) // Info 4164: (167-168): Inferred type: T(uint) // Info 4164: (180-192): Inferred type: U(string) // Info 4164: (183-192): Inferred type: U(string) @@ -59,11 +59,11 @@ function fun() { // Info 4164: (205-214): Inferred type: T(string) // Info 4164: (205-206): Inferred type: tfun(string, T(string)) // Info 4164: (207-213): Inferred type: string -// Info 4164: (220-228): Inferred type: T('cj:type) -// Info 4164: (220-225): Inferred type: U(string) -> T('cj:type) -// Info 4164: (220-221): Inferred type: U('cg:type) +// Info 4164: (220-228): Inferred type: T('bu:type) +// Info 4164: (220-225): Inferred type: U(string) -> T('bu:type) +// Info 4164: (220-221): Inferred type: U('bs:type) // Info 4164: (226-227): Inferred type: U(string) -// Info 4164: (234-242): Inferred type: U('cp:type) -// Info 4164: (234-239): Inferred type: T(string) -> U('cp:type) -// Info 4164: (234-235): Inferred type: U('cm:type) +// Info 4164: (234-242): Inferred type: U('by:type) +// Info 4164: (234-239): Inferred type: T(string) -> U('by:type) +// Info 4164: (234-235): Inferred type: U('bw:type) // Info 4164: (240-241): Inferred type: T(string) diff --git a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_instantiation_and_operators.sol b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_instantiation_and_operators.sol index b1cda1b3ed22..25ab330f3b32 100644 --- a/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_instantiation_and_operators.sol +++ b/test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_instantiation_and_operators.sol @@ -57,22 +57,22 @@ function fun(a: T(int: P3), b: T(str: P4)) { // Info 4164: (74-83): Inferred type: int // Info 4164: (84-93): Inferred type: str // Info 4164: (95-156): Inferred type: C -// Info 4164: (101-105): Inferred type: 'bf:(type, C) -// Info 4164: (115-154): Inferred type: ('bf:(type, C), 'bf:(type, C)) -> 'bf:(type, C) -// Info 4164: (127-145): Inferred type: ('bf:(type, C), 'bf:(type, C)) -// Info 4164: (128-135): Inferred type: 'bf:(type, C) -// Info 4164: (131-135): Inferred type: 'bf:(type, C) -// Info 4164: (137-144): Inferred type: 'bf:(type, C) -// Info 4164: (140-144): Inferred type: 'bf:(type, C) -// Info 4164: (149-153): Inferred type: 'bf:(type, C) +// Info 4164: (101-105): Inferred type: 'bd:(type, C) +// Info 4164: (115-154): Inferred type: ('bd:(type, C), 'bd:(type, C)) -> 'bd:(type, C) +// Info 4164: (127-145): Inferred type: ('bd:(type, C), 'bd:(type, C)) +// Info 4164: (128-135): Inferred type: 'bd:(type, C) +// Info 4164: (131-135): Inferred type: 'bd:(type, C) +// Info 4164: (137-144): Inferred type: 'bd:(type, C) +// Info 4164: (140-144): Inferred type: 'bd:(type, C) +// Info 4164: (149-153): Inferred type: 'bd:(type, C) // Info 4164: (158-175): Inferred type: P1 -// Info 4164: (164-168): Inferred type: 'bi:(type, P1) +// Info 4164: (164-168): Inferred type: 'bg:(type, P1) // Info 4164: (176-193): Inferred type: P2 -// Info 4164: (182-186): Inferred type: 'bl:(type, P2) +// Info 4164: (182-186): Inferred type: 'bj:(type, P2) // Info 4164: (194-211): Inferred type: P3 -// Info 4164: (200-204): Inferred type: 'cb:(type, P3) +// Info 4164: (200-204): Inferred type: 'bw:(type, P3) // Info 4164: (212-229): Inferred type: P4 -// Info 4164: (218-222): Inferred type: 'cd:(type, P4) +// Info 4164: (218-222): Inferred type: 'by:(type, P4) // Info 4164: (231-255): Inferred type: void // Info 4164: (256-280): Inferred type: void // Info 4164: (281-305): Inferred type: void @@ -80,56 +80,56 @@ function fun(a: T(int: P3), b: T(str: P4)) { // Info 4164: (332-356): Inferred type: void // Info 4164: (357-381): Inferred type: void // Info 4164: (383-458): Inferred type: void -// Info 4164: (398-405): Inferred type: 'cf:(type, P1) -// Info 4164: (399-404): Inferred type: 'cf:(type, P1) -// Info 4164: (402-404): Inferred type: 'cf:(type, P1) -// Info 4164: (415-456): Inferred type: (T('cf:(type, P1)), T('cf:(type, P1))) -> T('cf:(type, P1)) -// Info 4164: (427-445): Inferred type: (T('cf:(type, P1)), T('cf:(type, P1))) -// Info 4164: (428-435): Inferred type: T('cf:(type, P1)) -// Info 4164: (431-435): Inferred type: T('cf:(type, P1)) -// Info 4164: (431-432): Inferred type: tfun('cf:(type, P1), T('cf:(type, P1))) -// Info 4164: (433-434): Inferred type: 'cf:(type, P1) -// Info 4164: (437-444): Inferred type: T('cf:(type, P1)) -// Info 4164: (440-444): Inferred type: T('cf:(type, P1)) -// Info 4164: (440-441): Inferred type: tfun('cf:(type, P1), T('cf:(type, P1))) -// Info 4164: (442-443): Inferred type: 'cf:(type, P1) -// Info 4164: (449-453): Inferred type: T('cf:(type, P1)) -// Info 4164: (449-450): Inferred type: tfun('cf:(type, P1), T('cf:(type, P1))) -// Info 4164: (451-452): Inferred type: 'cf:(type, P1) +// Info 4164: (398-405): Inferred type: 'ca:(type, P1) +// Info 4164: (399-404): Inferred type: 'ca:(type, P1) +// Info 4164: (402-404): Inferred type: 'ca:(type, P1) +// Info 4164: (415-456): Inferred type: (T('ca:(type, P1)), T('ca:(type, P1))) -> T('ca:(type, P1)) +// Info 4164: (427-445): Inferred type: (T('ca:(type, P1)), T('ca:(type, P1))) +// Info 4164: (428-435): Inferred type: T('ca:(type, P1)) +// Info 4164: (431-435): Inferred type: T('ca:(type, P1)) +// Info 4164: (431-432): Inferred type: tfun('ca:(type, P1), T('ca:(type, P1))) +// Info 4164: (433-434): Inferred type: 'ca:(type, P1) +// Info 4164: (437-444): Inferred type: T('ca:(type, P1)) +// Info 4164: (440-444): Inferred type: T('ca:(type, P1)) +// Info 4164: (440-441): Inferred type: tfun('ca:(type, P1), T('ca:(type, P1))) +// Info 4164: (442-443): Inferred type: 'ca:(type, P1) +// Info 4164: (449-453): Inferred type: T('ca:(type, P1)) +// Info 4164: (449-450): Inferred type: tfun('ca:(type, P1), T('ca:(type, P1))) +// Info 4164: (451-452): Inferred type: 'ca:(type, P1) // Info 4164: (460-535): Inferred type: void -// Info 4164: (475-482): Inferred type: 'cs:(type, P2) -// Info 4164: (476-481): Inferred type: 'cs:(type, P2) -// Info 4164: (479-481): Inferred type: 'cs:(type, P2) -// Info 4164: (493-533): Inferred type: (T('cs:(type, P2)), T('cs:(type, P2))) -> bool -// Info 4164: (504-522): Inferred type: (T('cs:(type, P2)), T('cs:(type, P2))) -// Info 4164: (505-512): Inferred type: T('cs:(type, P2)) -// Info 4164: (508-512): Inferred type: T('cs:(type, P2)) -// Info 4164: (508-509): Inferred type: tfun('cs:(type, P2), T('cs:(type, P2))) -// Info 4164: (510-511): Inferred type: 'cs:(type, P2) -// Info 4164: (514-521): Inferred type: T('cs:(type, P2)) -// Info 4164: (517-521): Inferred type: T('cs:(type, P2)) -// Info 4164: (517-518): Inferred type: tfun('cs:(type, P2), T('cs:(type, P2))) -// Info 4164: (519-520): Inferred type: 'cs:(type, P2) +// Info 4164: (475-482): Inferred type: 'ck:(type, P2) +// Info 4164: (476-481): Inferred type: 'ck:(type, P2) +// Info 4164: (479-481): Inferred type: 'ck:(type, P2) +// Info 4164: (493-533): Inferred type: (T('ck:(type, P2)), T('ck:(type, P2))) -> bool +// Info 4164: (504-522): Inferred type: (T('ck:(type, P2)), T('ck:(type, P2))) +// Info 4164: (505-512): Inferred type: T('ck:(type, P2)) +// Info 4164: (508-512): Inferred type: T('ck:(type, P2)) +// Info 4164: (508-509): Inferred type: tfun('ck:(type, P2), T('ck:(type, P2))) +// Info 4164: (510-511): Inferred type: 'ck:(type, P2) +// Info 4164: (514-521): Inferred type: T('ck:(type, P2)) +// Info 4164: (517-521): Inferred type: T('ck:(type, P2)) +// Info 4164: (517-518): Inferred type: tfun('ck:(type, P2), T('ck:(type, P2))) +// Info 4164: (519-520): Inferred type: 'ck:(type, P2) // Info 4164: (526-530): Inferred type: bool // Info 4164: (537-618): Inferred type: void -// Info 4164: (552-565): Inferred type: 'bo:(type, P1, P2) -// Info 4164: (553-564): Inferred type: 'bo:(type, P1, P2) -// Info 4164: (556-564): Inferred type: 'bo:(type, P1, P2) -// Info 4164: (557-559): Inferred type: 'bo:(type, P1, P2) -// Info 4164: (561-563): Inferred type: 'bo:(type, P1, P2) -// Info 4164: (575-616): Inferred type: (T('bo:(type, P1, P2)), T('bo:(type, P1, P2))) -> T('bo:(type, P1, P2)) -// Info 4164: (587-605): Inferred type: (T('bo:(type, P1, P2)), T('bo:(type, P1, P2))) -// Info 4164: (588-595): Inferred type: T('bo:(type, P1, P2)) -// Info 4164: (591-595): Inferred type: T('bo:(type, P1, P2)) -// Info 4164: (591-592): Inferred type: tfun('bo:(type, P1, P2), T('bo:(type, P1, P2))) -// Info 4164: (593-594): Inferred type: 'bo:(type, P1, P2) -// Info 4164: (597-604): Inferred type: T('bo:(type, P1, P2)) -// Info 4164: (600-604): Inferred type: T('bo:(type, P1, P2)) -// Info 4164: (600-601): Inferred type: tfun('bo:(type, P1, P2), T('bo:(type, P1, P2))) -// Info 4164: (602-603): Inferred type: 'bo:(type, P1, P2) -// Info 4164: (609-613): Inferred type: T('bo:(type, P1, P2)) -// Info 4164: (609-610): Inferred type: tfun('bo:(type, P1, P2), T('bo:(type, P1, P2))) -// Info 4164: (611-612): Inferred type: 'bo:(type, P1, P2) +// Info 4164: (552-565): Inferred type: 'bm:(type, P1, P2) +// Info 4164: (553-564): Inferred type: 'bm:(type, P1, P2) +// Info 4164: (556-564): Inferred type: 'bm:(type, P1, P2) +// Info 4164: (557-559): Inferred type: 'bm:(type, P1, P2) +// Info 4164: (561-563): Inferred type: 'bm:(type, P1, P2) +// Info 4164: (575-616): Inferred type: (T('bm:(type, P1, P2)), T('bm:(type, P1, P2))) -> T('bm:(type, P1, P2)) +// Info 4164: (587-605): Inferred type: (T('bm:(type, P1, P2)), T('bm:(type, P1, P2))) +// Info 4164: (588-595): Inferred type: T('bm:(type, P1, P2)) +// Info 4164: (591-595): Inferred type: T('bm:(type, P1, P2)) +// Info 4164: (591-592): Inferred type: tfun('bm:(type, P1, P2), T('bm:(type, P1, P2))) +// Info 4164: (593-594): Inferred type: 'bm:(type, P1, P2) +// Info 4164: (597-604): Inferred type: T('bm:(type, P1, P2)) +// Info 4164: (600-604): Inferred type: T('bm:(type, P1, P2)) +// Info 4164: (600-601): Inferred type: tfun('bm:(type, P1, P2), T('bm:(type, P1, P2))) +// Info 4164: (602-603): Inferred type: 'bm:(type, P1, P2) +// Info 4164: (609-613): Inferred type: T('bm:(type, P1, P2)) +// Info 4164: (609-610): Inferred type: tfun('bm:(type, P1, P2), T('bm:(type, P1, P2))) +// Info 4164: (611-612): Inferred type: 'bm:(type, P1, P2) // Info 4164: (620-748): Inferred type: (T(int), T(str)) -> () // Info 4164: (632-662): Inferred type: (T(int), T(str)) // Info 4164: (633-646): Inferred type: T(int)