Skip to content

Commit

Permalink
Partially fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Jun 7, 2024
1 parent 5561ee4 commit d29873a
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions src/typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -2553,64 +2553,21 @@ def lookup_field_type(node: &parser::Node, state: &State, current_type: &Type, c
node = node.value.t_parr.tpe
}

if scope::is_global(state.scope) and (node.kind == parser::NodeKind::PTR_T or
if node.kind == parser::NodeKind::PTR_T or
node.kind == parser::NodeKind::REF_T or
node.kind == parser::NodeKind::ARRAY_T or
node.kind == parser::NodeKind::WEAK_REF_T or
node.kind == parser::NodeKind::FUNCTION_T or
node.kind == parser::NodeKind::CLOSURE_T) {
node.kind == parser::NodeKind::WEAK_REF_T {

if node.kind == parser::NodeKind::FUNCTION_T {
let box = box(type_lookup(node, state, current_type, false, cache))
box.size = size_of def [] -> []
box.align = align_of def [] -> []
return box
}
if node.kind == parser::NodeKind::CLOSURE_T {
let box = box(type_lookup(node, state, current_type, false, cache))
box.size = size_of [] -> []
box.align = align_of [] -> []
return box
}

var stub: &Type = null
let parr = node.value.t_parr.tpe
if parr {
parr.parent = node
if parr.tpe {
stub = parr.tpe
} else {
if parr.kind == parser::NodeKind::IDENTIFIER {
stub = make_stub_type(parr, state)
} else {
stub = make_type_raw(TypeKind::STUB)
}
stub.state = consteval::copy_state(state)
stub.module = state.module
stub.node = parr
parr.tpe = stub
}
}

if prev_node.kind == parser::NodeKind::PTR_T {
stub = pointer(stub, node.value.t_parr.kw)
} else if prev_node.kind == parser::NodeKind::REF_T {
stub = reference(stub, node.value.t_parr.kw)
} else if prev_node.kind == parser::NodeKind::ARRAY_T {
stub = array(stub, node.value.t_parr.kw)
}
var stub = type_lookup(node, state, current_type, false, cache)
stub._tpe = box(stub._tpe)

if prev_node.kind == parser::NodeKind::WEAK_REF_T {
stub = weak_reference(stub, node.value.t_parr.kw)
stub.module = state.module
stub.node = node
prev_node.tpe = stub
} else {
stub.module = state.module
stub.node = node
node.tpe = stub
}

return stub
} else {
return type_lookup(node, state, current_type, false, cache)
Expand Down Expand Up @@ -2828,7 +2785,7 @@ export def do_type_lookup(node: &parser::Node, state: &State, current_type: &Typ

let arg = node.value.t_func.args(i)
let np = [
_tpe = type_lookup(arg, state, arg_type, lookup_default, cache),
_tpe = box(type_lookup(arg, state, arg_type, lookup_default, cache)),
node = arg
] !NamedParameter
tpe.parameter_t.push(np)
Expand All @@ -2844,6 +2801,7 @@ export def do_type_lookup(node: &parser::Node, state: &State, current_type: &Typ
}

let arg = node.value.t_func.ret(i)
// TODO This needs to be boxed as well, potential memory leak
let ret_tpe = type_lookup(arg, state, return_type, lookup_default, cache)

tpe.return_t.push(ret_tpe)
Expand Down

0 comments on commit d29873a

Please sign in to comment.