Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated naming conventions #84

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d38fd06
Try new naming conventions on lists
elaustell Jul 31, 2024
281a31c
add rev
elaustell Jul 31, 2024
5d3a937
Polishing, tidying, renaming, some comments
Jul 31, 2024
5934f2d
Summary of proposed naming conventions
Jul 31, 2024
c8b4bd8
rename `list_cn_types` to `Seq.h`
elaustell Aug 1, 2024
7e65961
Tidying
Aug 1, 2024
92751b8
Merge branch 'naming_conventions' of https://github.com/rems-project/…
Aug 1, 2024
fb6c311
Instructions
Aug 1, 2024
1eeb5ef
Rename Seq.h back to list_cn_types.h (lighter)
Aug 1, 2024
c3bded0
Better proposal for conventions
Aug 1, 2024
32e5a6b
add Liz opinions
elaustell Aug 1, 2024
fa952aa
Responses to Liz and some more polishing
Aug 2, 2024
d21f25f
Updated naming convention recommendations (WIP)
Aug 8, 2024
1f903e1
Tiny bit of renaming in progress
Aug 12, 2024
2dd9ed0
Checkpoint renaming in progress
Aug 14, 2024
8861f70
Checkpoint further progress -- not ready for review yet
Aug 14, 2024
3f803d4
Makefile nit
Aug 14, 2024
a76ec94
'nother round of renaming
Aug 14, 2024
346078f
Merge remote-tracking branch 'origin/main' into naming_conventions
Aug 14, 2024
9094b86
WIP tutorial polishing
Aug 16, 2024
a048a72
More WIP on tutorial
Aug 16, 2024
3907502
More tutorial WIP
Aug 16, 2024
b0e8343
WIP on tutorial
Aug 16, 2024
17ea167
WIP renaming
Aug 16, 2024
6b3f3d1
WIP more renaming and polishing
Aug 18, 2024
e943a95
change cn invocation instructions to cn verify
dsainati1 Aug 19, 2024
6f032b8
add sentence about ternary operator precdence
dsainati1 Aug 19, 2024
b7733b9
WIP more renaming and polishing
Aug 19, 2024
06863c3
place exercises for resources after the section on linear ownership
dsainati1 Aug 19, 2024
0bd03d9
add comment on second extract argument
dsainati1 Aug 19, 2024
ccba8b3
add explanation about unfold
dsainati1 Aug 19, 2024
5f4357f
prove pop returns the old head
dsainati1 Aug 19, 2024
9de0de0
add some TODOs
dsainati1 Aug 19, 2024
61033a1
WIP bunch more renaming and polishing
Aug 19, 2024
2c7b117
Record some conversations about TODOs
Aug 23, 2024
9d812d1
Merge remote-tracking branch 'origin/main' into naming-conventions-2
Aug 23, 2024
1e8f59e
Merge remote-tracking branch 'origin/tutorial-feedback' into naming-c…
Aug 23, 2024
de6d882
Tidy merge
Aug 23, 2024
da6f42e
Tidying per github discussion
Aug 30, 2024
afb8b5e
Start fixing queue examples
Aug 30, 2024
2b6dce7
renaming
Aug 30, 2024
6429b35
Bit more polishing on renaming
Aug 30, 2024
c0f4575
Further polishing (queues)
Aug 30, 2024
f4e9498
(queues)
Aug 30, 2024
f28cd4e
Tutorial: work on DLL example
Sep 1, 2024
93a1609
Tutorial WIP
Sep 1, 2024
9bf52a7
Merge branch 'naming-conventions-2' of https://github.com/rems-projec…
Sep 1, 2024
5968408
Polish DLL and Runway case studies
Sep 1, 2024
5a47724
Queue -> Queue_At
Sep 1, 2024
088f9e9
Rename most predicates P to P_At
Sep 1, 2024
46add80
CP
Sep 1, 2024
e0de380
Remove unused example
Sep 1, 2024
8096c34
Move queue files to /queue subdir
Sep 1, 2024
648d8d0
Rename list_ examples
Sep 1, 2024
f265ca1
Merge in Apol's BST example and start renaming
Sep 1, 2024
2ecca6d
CP
Sep 1, 2024
b9141ee
CP
Sep 1, 2024
b230220
CP
Sep 1, 2024
7c0d972
Polish BST naming conventions and move it out of the main tutorial (bc
Sep 1, 2024
2c2155f
Actually move files
Sep 1, 2024
4bf0b12
Tidy
Sep 1, 2024
e46875f
Merge branch 'main' into naming-conventions-2
bcpierce00 Sep 1, 2024
c554f75
Merge
Sep 1, 2024
8de5497
Merge branch 'naming-conventions-2' of https://github.com/rems-projec…
Sep 1, 2024
d44464b
Merge branch 'main' into naming-conventions-2
Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
MAKEFILE_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST))))

default: build exercises build/tutorial.html build/exercises.zip
all: default

clean:
rm -rf build TAGS
Expand Down Expand Up @@ -43,6 +44,10 @@ build/solutions/%: src/examples/%
build/exercises.zip: $(EXERCISES)
cd build; zip -r exercises.zip exercises > /dev/null

WORKING=$(wildcard src/examples/list_*.c)
WORKING_AUX=$(patsubst src/examples/%, build/solutions/%, $(WORKING))
temp: $(WORKING_AUX) build
# build/tutorial.html

##############################################################################
# Check that the examples all run correctly
Expand Down
105 changes: 105 additions & 0 deletions NAMING-CONVENTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
CN Naming Conventions
---------------------

This document describes our (Benjamin and Liz's) current best shot at
a good set of conventions for naming identifiers in CN, based on
numerous discussions and worked examples. Everything in the tutorial
(in src/examples) follows these conventions. Future CN coders are
encouraged to follow suit.

# Principles

- When similar concepts exist in both C and CN, they should be named
so that the correspondence is immediately obvious.
- In particular, the C and CN versions of a given data structure
should have very similar names.

- In text, we use the modifiers _CN-level_ vs. _C-level_ to
distinguish the two worlds.

# General conventions

## For new code

When writing both C and CN code from scratch (e.g., in the tutorial),
aim for maximal correspondence between

- In general, identifiers are written in `snake_case` (or
`Snake_Case`) rather than `camlCase` (or `CamlCase`).

- C-level identifiers are `lowercase` wherever possible.

- CN-level identifiers are `Uppercase_Consistently_Throughout`.

- A CN identifier that represents the state of a mutable data
structure after some function returns should be named the same as
the starting state of the data structure, with an `_post` at the
end.
- E.g., The list copy function takes a linked list `l`
representing a sequence `L` and leaves `l` at the end pointing
to a final sequence `L_post` such that `L == L_post`.
(Moreover, it returns a new sequence `Ret` with `L == Ret`.)

- Predicates that extract some structure from the heap should be named
the same as the structure they extract, plus the suffix `_At`.
E.g., the result type of the `Queue` predicate is also called
`Queue_At`.

## For existing code

In existing C codebases, uppercase-initial identifiers are often used
for typedefs, structs, and enumerations. We should choose a
recommended standard convention for such cases -- e.g., "prefix
CN-level identifiers with `CN` when needed to avoid confusion with
C-level identifiers". Some experimentation will be needed to see
which convention we like best; this is left for future discussions.

# Built-ins

This proposal may ultimately suggest changing some built-ins for
consistency.

- `i32` should change to `I32`, `u64` to `U64`
- `is_null` to `Is_null` (or `Is_Null`)

*Discussion*: One point against this change is that CN currently tries
to use names reminiscent of Rust (`i32`, `u64`, etc.). I (BCP) do not
personally find this argument persuasive -- internal consistency seems
more important than miscellaeous points of similarity with some other
language. One way or the other, this will require a global decision.

# Polymorphism

One particularly tricky issue is how to name the "monomorphic
instances" of "morally polymorphic" functions (i.e., whether to write
`append__Int` or `append__List_Int` rather than just `append`). On
one hand, `append__Int` is "more correct". On the other hand, these
extra annotations can get pretty heavy.

We propose a compromise:

1. If a project needs to use two or more instances of some polymorphic
type, then the names of the C and CN types, the C and CN functions
operating over them, and the CN predicates describing them are all
suffixed with `__xxx`, where `xxx` is the appropriate "type
argument". E.g., if some codebase uses lists of both signed and
unsigned 32-bit ints, then we would use names like this:
- `list__int` / `list__uint`
- `append__int` / `append__uint`
- `List__I32` / `List__U32`
- `Cons__I32` / `Cons__U32`
- etc.

2. However, if, in a given project, a set of "morally polymorphic"
type definitions and library functions is *only used at one
monomorphic instance* (e.g., if some codebase only ever uses lists
of 32-bit signed ints), then the `__int` or `__I32` annotations are
omitted.

This convention is used in the CN tutorial, for example.

*Discussion*: One downside of this convention is that it might
sometimes require some after-the-fact renaming: If a project starts
out using just lists of signed ints and later needs to introduce lists
of unsigned ints, the old signed operations will need to be renamed.
This seems like an acceptable cost for keeping things light.
2 changes: 1 addition & 1 deletion src/example-archive/SAW/broken/error-cerberus/00001.swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let argmin_spec len = do {

// NOTE: Another mistake I made was to use the override below.
// This works for size a_len, but on the second time through the loop the override
// doesn't match because the size of the list has changed! Ultimately need a
// doesn't match because the size of the ./headers.has changed! Ultimately need a
// loop here.

{-/
Expand Down
6 changes: 3 additions & 3 deletions src/example-archive/simple-examples/working/malloc_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
// malloc() is not defined by default in CN. We can define a fake malloc()
// function that only works on ints.

int *my_malloc_int()
int *my_malloc__int()
/*@ trusted; @*/
/*@ ensures take New = Block<int>(return); @*/
{}

int *malloc_1()
int *malloc__1()
/*@ ensures
take New = Owned<int>(return);
New == 7i32;
*return == 7i32; @*/ // <-- Alternative syntax
{
int *new;
new = my_malloc_int();
new = my_malloc__int();
*new = 7; // Have to initialize the memory before it's owned
return new;
}
9 changes: 0 additions & 9 deletions src/examples/3.c

This file was deleted.

35 changes: 0 additions & 35 deletions src/examples/Dbl_Linked_List/add.c

This file was deleted.

27 changes: 0 additions & 27 deletions src/examples/Dbl_Linked_List/add_orig.broken.c

This file was deleted.

5 changes: 0 additions & 5 deletions src/examples/Dbl_Linked_List/c_types.h

This file was deleted.

6 changes: 0 additions & 6 deletions src/examples/Dbl_Linked_List/cn_types.h

This file was deleted.

22 changes: 0 additions & 22 deletions src/examples/Dbl_Linked_List/getters.h

This file was deleted.

12 changes: 0 additions & 12 deletions src/examples/Dbl_Linked_List/malloc_free.h

This file was deleted.

17 changes: 0 additions & 17 deletions src/examples/Dbl_Linked_List/node_and_int.h

This file was deleted.

36 changes: 0 additions & 36 deletions src/examples/Dbl_Linked_List/predicates.h

This file was deleted.

36 changes: 0 additions & 36 deletions src/examples/Dbl_Linked_List/remove.c

This file was deleted.

13 changes: 0 additions & 13 deletions src/examples/Dbl_Linked_List/singleton.c

This file was deleted.

Loading