Skip to content

Commit 179cfbd

Browse files
committed
frontend: utilize BoundBaseType.mutabilityUpperBound to simplify decoration
1 parent bad4988 commit 179cfbd

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

frontend/src/main/kotlin/compiler/ast/BaseTypeDeclaration.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ class BaseTypeMemberVariableDeclaration(
102102
false
103103
}
104104

105-
val isMutabilityTiedToParentObject: Boolean =
106-
attributes.ownership == BoundBaseTypeMemberVariable.Ownership.OWNED &&
107-
variableDeclaration.type?.mutability == null
108-
109105
inner class Binder(val typeRootContext: CTContext) {
110106
val isConstructorParameterInitialized: Boolean = this@BaseTypeMemberVariableDeclaration.isConstructorParameterInitialized
111-
val isMutabilityTiedToParentObject: Boolean = this@BaseTypeMemberVariableDeclaration.isMutabilityTiedToParentObject
112-
val mayNeedConstructorTypeParameter: Boolean get()= needsCtorTypeParameter != false
113107

114-
private var needsCtorTypeParameter: Boolean? = if (isConstructorParameterInitialized && isMutabilityTiedToParentObject) null /* not yet known*/ else false /* definitely not */
108+
private val isOwned: Boolean = attributes.ownership == BoundBaseTypeMemberVariable.Ownership.OWNED
109+
private var needsCtorTypeParameter: Boolean? = if (isConstructorParameterInitialized && isOwned) null /* not yet known*/ else false /* definitely not */
115110
private var ctorTypeParameter: BoundTypeParameter? = null
111+
val mayNeedConstructorTypeParameter: Boolean get()= needsCtorTypeParameter != false
112+
private val resolvedType: BoundTypeReference? by lazy {
113+
variableDeclaration.type?.let(typeRootContext::resolveType)
114+
}
115+
private val isMutabilityTiedToParentObject: Boolean get() = isOwned && resolvedType?.mutability in setOf(null, TypeMutability.top())
116116

117117
fun generateTypeParameterForConstructor(
118118
contextBeforeCtorFunctionRoot: CTContext,
@@ -131,13 +131,10 @@ class BaseTypeMemberVariableDeclaration(
131131
needsCtorTypeParameter = false
132132
return null
133133
}
134-
if (declaredType != null) {
135-
val resolvedType = typeRootContext.resolveType(declaredType)
136-
if (resolvedType.mutability != TypeMutability.top()) {
137-
// mutability is pre-determined, no need to parameterize the constructor
138-
needsCtorTypeParameter = false
139-
return null
140-
}
134+
if (resolvedType?.mutability !in setOf(null, TypeMutability.top())) {
135+
// mutability is pre-determined, no need to parameterize the constructor
136+
needsCtorTypeParameter = false
137+
return null
141138
}
142139
needsCtorTypeParameter = true
143140

@@ -239,6 +236,7 @@ class BaseTypeMemberVariableDeclaration(
239236
attributes,
240237
baseType,
241238
this@BaseTypeMemberVariableDeclaration,
239+
isMutabilityTiedToParentObject,
242240
)
243241
}
244242

frontend/src/main/kotlin/compiler/binding/basetype/BoundBaseTypeMemberVariable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class BoundBaseTypeMemberVariable(
4242
val attributes: BoundBaseTypeMemberVariableAttributes,
4343
private val baseType: BoundBaseType,
4444
override val entryDeclaration: BaseTypeMemberVariableDeclaration,
45+
val isMutabilityTiedToParentObject: Boolean,
4546
) : BoundBaseTypeEntry<BaseTypeMemberDeclaration>, DefinitionWithVisibility {
4647
val name = entryDeclaration.name.value
4748
override val declaredAt = entryDeclaration.span
4849
val isReAssignable = entryDeclaration.variableDeclaration.isReAssignable
4950
val isConstructorParameterInitialized: Boolean = entryDeclaration.isConstructorParameterInitialized
50-
val isMutabilityTiedToParentObject: Boolean = entryDeclaration.isMutabilityTiedToParentObject
5151

5252
private val seanHelper = SeanHelper()
5353

llvm-backend/src/main/emerge-ffi-c/types.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package emerge.ffi.c
22

33
export class COpaquePointer {
4-
private pointed: Any = init
4+
ref private pointed: Any = init
55
}
66

77
export class CPointer<T> {

0 commit comments

Comments
 (0)