source: doc/proposals/function_type_change.md @ 3ada8ae

arm-ehjacob/cs343-translationnew-ast-unique-expr
Last change on this file since 3ada8ae was 954c954, checked in by Fangren Yu <f37yu@…>, 13 months ago

Move function argument and return variable declarations from FunctionType? to FunctionDecl?

  • Property mode set to 100644
File size: 2.0 KB
Line 
1## Eliminate Variable Declarations in Function Type ##
2
3The parameters of a function had been living in the wrong place.
4
5As the function type has no relation with the actual declarations of the variables, but only the types of them, putting declarations in FunctionType is unnecessary.
6Meanwhile, in new-ast data model, the declaration nodes should be kept as unique as possible, since they semantically denote unique objects in the source code. Shared declarations often lead to undesirable behaviors, especially when weak references exist (reminder: currently weak references only point to declarations). They also pose difficulty for implementing correct _functional_ algorithms, as copying a declaration node _should_ always mean creating a new entity.
7In the programming language and type theory model, declarations are also never a part of function type; the functions `int f(int a)` and `int f(int b)` have the exact same type (int)->(int), and representing the type as (int a)->(int b) is misleading.
8
9
10## Summary of Changes ##
11
12- `ast::FunctionDecl`
13Now owns its parameter and return variables directly.
14
15- `ast::FunctionType`
16Parameter and return types are now pure types (no more decls)
17Forall clause is part of type information so it is still kept.
18
19- Unify.cc
20Renamed some functions to reflect the changes (decl -> type)
21
22- Convert.cpp
23Drop decls in function type, unless it is directly in function decl (move them to `FunctionDecl` params and returns)
24Add dummy variable decls while converting back.
25
26## Relevant Clean-up Work ##
27
28- CurrentObject.cpp
29No longer has weak references to type nodes and replaced by raw pointers. Using weak pointers do not accomplish anything since a non in-place mutation outside invalidates current iterator anyways and an in-place mutation outside is still seen by the iterator with just a raw pointer.
30
31- Validate.cc
32`EnumAndPointerDecay` is redundant in `resolveTypeof` and therefore dropped.
33Note: this pass needs some structural change to accommodate the new function type representation.
34
Note: See TracBrowser for help on using the repository browser.