Skip to content

Commit d399d3d

Browse files
committed
Removed old reference-counting and lifetime analysis code
1 parent 02ec1e0 commit d399d3d

File tree

28 files changed

+41
-840
lines changed

28 files changed

+41
-840
lines changed

Diff for: src/ast/datatype/kind/display.rs

-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ impl Display for &TypeKind {
2929
TypeKind::Pointer(inner) => {
3030
write!(f, "ptr<{inner}>")?;
3131
}
32-
TypeKind::PlainOldData(inner) => {
33-
write!(f, "pod<{inner}>")?;
34-
}
3532
TypeKind::Void => {
3633
write!(f, "void")?;
3734
}

Diff for: src/ast/datatype/kind/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub enum TypeKind {
1515
Floating(FloatSize),
1616
Pointer(Box<Type>),
1717
FixedArray(Box<FixedArray>),
18-
PlainOldData(Box<Type>),
1918
Void,
2019
Named(String),
2120
AnonymousStruct(AnonymousStruct),

Diff for: src/ast/structure/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub struct Structure {
77
pub name: String,
88
pub fields: IndexMap<String, Field>,
99
pub is_packed: bool,
10-
pub prefer_pod: bool,
1110
pub source: Source,
1211
}
1312

Diff for: src/c/translation/types/composite.rs

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub fn make_composite(
9595
name: name.clone(),
9696
fields,
9797
is_packed,
98-
prefer_pod: true,
9998
source: composite.source,
10099
});
101100

Diff for: src/interpreter_env/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
108108
},
109109
)]),
110110
is_packed: false,
111-
prefer_pod: false,
112111
source,
113112
});
114113

Diff for: src/ir/mod.rs

-23
Original file line numberDiff line numberDiff line change
@@ -377,29 +377,6 @@ impl Type {
377377
Type::Pointer(Box::new(self.clone()))
378378
}
379379

380-
pub fn reference_counted_pointer(&self) -> Self {
381-
// Don't allow wrapping pointer values with reference counting
382-
// This will catch us if we accidentally nest more than once
383-
assert!(!self.is_pointer());
384-
385-
Type::Pointer(Box::new(self.reference_counted_no_pointer()))
386-
}
387-
388-
pub fn reference_counted_no_pointer(&self) -> Self {
389-
let subtypes = vec![
390-
// Reference count
391-
Field::basic(Type::U64, Source::internal()),
392-
// Value
393-
Field::basic(self.clone(), Source::internal()),
394-
];
395-
396-
Type::AnonymousComposite(TypeComposite {
397-
fields: subtypes,
398-
is_packed: false,
399-
source: Source::internal(),
400-
})
401-
}
402-
403380
pub fn is_integer_like(&self) -> bool {
404381
matches!(
405382
self,

Diff for: src/lower/mod.rs

+3-139
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,7 @@ fn lower_stmts(
216216

217217
for stmt in stmts.iter() {
218218
result = match &stmt.kind {
219-
StmtKind::Return(expr, drops) => {
220-
for variable_key in drops.drops.iter() {
221-
lower_drop(
222-
builder,
223-
&ir_module.target,
224-
*variable_key,
225-
function,
226-
resolved_ast,
227-
)?;
228-
}
229-
219+
StmtKind::Return(expr) => {
230220
let instruction = ir::Instruction::Return(if let Some(expr) = expr {
231221
Some(lower_expr(
232222
builder,
@@ -311,43 +301,11 @@ fn lower_stmts(
311301
Value::Literal(Literal::Void)
312302
}
313303
};
314-
315-
for variable_key in stmt.drops.iter() {
316-
lower_drop(
317-
builder,
318-
&ir_module.target,
319-
*variable_key,
320-
function,
321-
resolved_ast,
322-
)?;
323-
}
324304
}
325305

326306
Ok(result)
327307
}
328308

329-
fn lower_drop(
330-
builder: &mut Builder,
331-
target: &Target,
332-
variable_key: VariableStorageKey,
333-
function: &resolved::Function,
334-
resolved_ast: &resolved::Ast,
335-
) -> Result<(), LowerError> {
336-
let variable = function
337-
.variables
338-
.get(variable_key)
339-
.expect("referenced variable to exist");
340-
341-
if variable.resolved_type.kind.is_managed_structure() {
342-
let variable_pointer = lower_variable_to_value(variable_key);
343-
let variable_type = lower_type(target, &variable.resolved_type, resolved_ast)?;
344-
let heap_pointer = builder.push(ir::Instruction::Load((variable_pointer, variable_type)));
345-
builder.push(ir::Instruction::Free(heap_pointer));
346-
}
347-
348-
Ok(())
349-
}
350-
351309
fn lower_type(
352310
target: &Target,
353311
resolved_type: &resolved::Type,
@@ -390,12 +348,7 @@ fn lower_type(
390348
resolved_ast,
391349
)?))),
392350
resolved::TypeKind::Void => Ok(ir::Type::Void),
393-
resolved::TypeKind::ManagedStructure(_, structure_ref) => {
394-
Ok(ir::Type::Structure(*structure_ref).reference_counted_pointer())
395-
}
396-
resolved::TypeKind::PlainOldData(_, structure_ref) => {
397-
Ok(ir::Type::Structure(*structure_ref))
398-
}
351+
resolved::TypeKind::Structure(_, structure_ref) => Ok(ir::Type::Structure(*structure_ref)),
399352
resolved::TypeKind::AnonymousStruct() => {
400353
todo!("lower anonymous struct")
401354
}
@@ -450,33 +403,11 @@ fn lower_destination(
450403
subject,
451404
structure_ref,
452405
index,
453-
memory_management,
454406
..
455407
} => {
456408
let subject_pointer =
457409
lower_destination(builder, ir_module, subject, function, resolved_ast)?;
458410

459-
let subject_pointer = match memory_management {
460-
resolved::MemoryManagement::None => subject_pointer,
461-
resolved::MemoryManagement::ReferenceCounted => {
462-
// Load pointer from pointed object
463-
464-
let struct_type =
465-
ir::Type::Structure(*structure_ref).reference_counted_no_pointer();
466-
467-
let subject_pointer = builder.push(ir::Instruction::Load((
468-
subject_pointer,
469-
struct_type.pointer(),
470-
)));
471-
472-
builder.push(ir::Instruction::Member {
473-
struct_type,
474-
subject_pointer,
475-
index: 1,
476-
})
477-
}
478-
};
479-
480411
Ok(builder.push(ir::Instruction::Member {
481412
subject_pointer,
482413
struct_type: ir::Type::Structure(*structure_ref),
@@ -733,36 +664,11 @@ fn lower_expr(
733664
structure_ref,
734665
index,
735666
field_type,
736-
memory_management,
737667
} = &**member;
738668

739669
let subject_pointer =
740670
lower_destination(builder, ir_module, subject, function, resolved_ast)?;
741671

742-
let subject_pointer = match memory_management {
743-
resolved::MemoryManagement::None => subject_pointer,
744-
resolved::MemoryManagement::ReferenceCounted => {
745-
// Take off reference counted wrapper
746-
747-
// Get inner structure type
748-
let struct_type =
749-
ir::Type::Structure(*structure_ref).reference_counted_no_pointer();
750-
751-
// Load pointer to referece counted wrapper
752-
let subject_pointer = builder.push(ir::Instruction::Load((
753-
subject_pointer,
754-
struct_type.pointer(),
755-
)));
756-
757-
// Obtain pointer to inner data
758-
builder.push(ir::Instruction::Member {
759-
subject_pointer,
760-
struct_type,
761-
index: 1,
762-
})
763-
}
764-
};
765-
766672
// Access member of structure
767673
let member = builder.push(ir::Instruction::Member {
768674
subject_pointer,
@@ -802,7 +708,6 @@ fn lower_expr(
802708
let StructureLiteral {
803709
structure_type,
804710
fields,
805-
memory_management,
806711
} = &**structure_literal;
807712

808713
let result_ir_type = lower_type(&ir_module.target, structure_type, resolved_ast)?;
@@ -820,48 +725,7 @@ fn lower_expr(
820725
// Drop the index part of the values
821726
let values = values.drain(..).map(|(_, value)| value).collect();
822727

823-
match memory_management {
824-
resolved::MemoryManagement::None => {
825-
Ok(builder.push(ir::Instruction::StructureLiteral(result_ir_type, values)))
826-
}
827-
resolved::MemoryManagement::ReferenceCounted => {
828-
let flat = builder.push(ir::Instruction::StructureLiteral(
829-
result_ir_type.clone(),
830-
values,
831-
));
832-
833-
let wrapper_struct_type = result_ir_type.reference_counted_no_pointer();
834-
835-
let heap_memory =
836-
builder.push(ir::Instruction::Malloc(wrapper_struct_type.clone()));
837-
838-
// TODO: Assert that malloc didn't return NULL
839-
840-
let at_reference_count = builder.push(ir::Instruction::Member {
841-
subject_pointer: heap_memory.clone(),
842-
struct_type: wrapper_struct_type.clone(),
843-
index: 0,
844-
});
845-
846-
builder.push(ir::Instruction::Store(ir::Store {
847-
new_value: ir::Value::Literal(Literal::Unsigned64(1)),
848-
destination: at_reference_count,
849-
}));
850-
851-
let at_value = builder.push(ir::Instruction::Member {
852-
subject_pointer: heap_memory.clone(),
853-
struct_type: wrapper_struct_type.clone(),
854-
index: 1,
855-
});
856-
857-
builder.push(ir::Instruction::Store(ir::Store {
858-
new_value: flat,
859-
destination: at_value,
860-
}));
861-
862-
Ok(heap_memory)
863-
}
864-
}
728+
Ok(builder.push(ir::Instruction::StructureLiteral(result_ir_type, values)))
865729
}
866730
ExprKind::UnaryOperation(unary_operation) => {
867731
let inner = lower_expr(

Diff for: src/parser/annotation.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub enum AnnotationKind {
1818
Foreign,
1919
ThreadLocal,
2020
Packed,
21-
Pod,
2221
AbideAbi,
2322
}
2423

@@ -34,7 +33,6 @@ impl Display for AnnotationKind {
3433
Self::Foreign => "foreign",
3534
Self::ThreadLocal => "thread_local",
3635
Self::Packed => "packed",
37-
Self::Pod => "pod",
3836
Self::AbideAbi => "abide_abi",
3937
})
4038
}

Diff for: src/parser/parse_annotation.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
2525
"foreign" => AnnotationKind::Foreign,
2626
"thread_local" => AnnotationKind::ThreadLocal,
2727
"packed" => AnnotationKind::Packed,
28-
"pod" => AnnotationKind::Pod,
2928
"abide_abi" => AnnotationKind::AbideAbi,
3029
_ => {
3130
return Err(ParseErrorKind::UnrecognizedAnnotation {

Diff for: src/parser/parse_structure.rs

-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
2222
self.ignore_newlines();
2323

2424
let mut is_packed = false;
25-
let mut prefer_pod = false;
2625

2726
for annotation in annotations {
2827
match annotation.kind {
2928
AnnotationKind::Packed => is_packed = true,
30-
AnnotationKind::Pod => prefer_pod = true,
3129
_ => return Err(self.unexpected_annotation(&annotation, Some("for structure"))),
3230
}
3331
}
@@ -66,7 +64,6 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
6664
name,
6765
fields,
6866
is_packed,
69-
prefer_pod,
7067
source,
7168
})
7269
}

Diff for: src/parser/parse_type.rs

-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
8686
count,
8787
})))
8888
}
89-
"pod" => {
90-
self.parse_token(TokenKind::OpenAngle, Some("to specify inner type of 'pod'"))?;
91-
let inner = self.parse_type(None::<&str>, None::<&str>)?;
92-
self.parse_type_parameters_close()?;
93-
Ok(TypeKind::PlainOldData(Box::new(inner)))
94-
}
9589
identifier => Ok(TypeKind::Named(identifier.into())),
9690
}?;
9791

Diff for: src/resolve/core_structure_info.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
use super::error::{ResolveError, ResolveErrorKind};
22
use crate::{
3-
resolved::{self, MemoryManagement, StructureRef},
3+
resolved::{self, StructureRef},
44
source_files::Source,
55
};
66

77
pub fn get_core_structure_info(
88
resolved_type: &resolved::Type,
99
source: Source,
10-
) -> Result<(&str, StructureRef, MemoryManagement), ResolveError> {
10+
) -> Result<(&str, StructureRef), ResolveError> {
1111
match &resolved_type.kind {
12-
resolved::TypeKind::PlainOldData(name, structure_ref) => {
13-
Ok((name, *structure_ref, resolved::MemoryManagement::None))
12+
resolved::TypeKind::Structure(name, structure_ref) => Ok((name, *structure_ref)),
13+
_ => Err(ResolveErrorKind::CannotCreateStructLiteralForNonStructure {
14+
bad_type: resolved_type.to_string(),
1415
}
15-
resolved::TypeKind::ManagedStructure(name, structure_ref) => Ok((
16-
name,
17-
*structure_ref,
18-
resolved::MemoryManagement::ReferenceCounted,
19-
)),
20-
_ => Err(
21-
ResolveErrorKind::CannotCreateStructLiteralForNonPlainOldDataStructure {
22-
bad_type: resolved_type.to_string(),
23-
}
24-
.at(source),
25-
),
16+
.at(source)),
2617
}
2718
}

0 commit comments

Comments
 (0)