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

Refactoring #94

Merged
merged 10 commits into from
Sep 14, 2024
Merged

Refactoring #94

merged 10 commits into from
Sep 14, 2024

Conversation

fpottier
Copy link
Collaborator

@fpottier fpottier commented Sep 7, 2024

This PR introduces the functions expand_ident and expand_macro_application so as to clarify how identifiers are treated by cppo. In particular, in the case where an identifier is not a macro, the code is significantly simpler than before; it is now clear that such an identifier is treated as text.

There should be no change in functionality.

I wanted to propose this simplification before introducing support for #scope ... #endscope.

[expand_macro_application], for better readability.
This leads to a better type error message when the definition
of the type [node] evolves.
[expand_list] always preserves [enable_loc]. (Proof: every update of
[g.enable_loc] is protected by a call to [preserving_enable_loc].)
So, protecting a call to [expand_list] with [preserving_enable_loc]
is unnecessary.
…= false].

The previous call to [expand_list ... (text ...)] always leaves
[g.require_location] set to [false]. (Proof: [text ...] always
ends with a non-space [`Text] item, and processing such an item
sets [g.require_location] to [false].)

So, this change should not have any impact, and it makes the code
cleaner. Ideally, [expand_ordinary_ident] should be a one-line
function. We are almost there.
…_loc].

This makes no difference, I believe. Proof (sketch): [g.call_loc] is read
only when the macros __FILE__, __LINE__ or CONCAT are expanded. So it is
sufficient to update at macro invocations. There is no need to update it
here.
This function is now just a one-liner, so it can be expanded away.
@pmetzger
Copy link
Member

pmetzger commented Sep 8, 2024

What testing did you do to make sure the functionality remained the same?

@fpottier
Copy link
Collaborator Author

fpottier commented Sep 9, 2024

I just verified that make test still succeeds.

If you think that the current test suite is too small, I would be happy to strengthen it. We could for instance copy the source code of some packages that have a heavy dependency on cppo and integrate it in the test suite?

@fpottier
Copy link
Collaborator Author

fpottier commented Sep 9, 2024

Or perhaps I could create a script that performs a more heavyweight test, such as creating a fresh opam switch, installing cppo, and compiling a bunch of packages that depend (directly) on cppo. (This would allow checking that these packages can be still compiled, but would not allow us to detect a situation where the output of cppo changes slightly.)

@liyishuai
Copy link
Member

Or perhaps I could create a script that performs a more heavyweight test, such as creating a fresh opam switch, installing cppo, and compiling a bunch of packages that depend (directly) on cppo. (This would allow checking that these packages can be still compiled, but would not allow us to detect a situation where the output of cppo changes slightly.)

I think that's part of the CI (which is passing):

- name: Test dependants
if: >
(matrix.ocaml-version >= '4.05') && (matrix.os != 'windows-latest')
run: |
PACKAGES=`opam list -s --color=never --installable --depends-on cppo,cppo_ocamlbuild`
echo "Dependants:" $PACKAGES
for PACKAGE in $PACKAGES
do
echo $SKIP_BUILD | tr ' ' '\n' | grep ^$PACKAGE$ > /dev/null &&
echo Skip $PACKAGE && continue
OPAMWITHTEST=true
echo $SKIP_TEST | tr ' ' '\n' | grep ^$PACKAGE$ > /dev/null &&
OPAMWITHTEST=false
([ $OPAMWITHTEST == false ] &&
echo ::group::Build $PACKAGE) ||
echo ::group::Build and test $PACKAGE
DEPS_FAILED=false
(opam depext $PACKAGE &&
opam install --deps-only $PACKAGE) || DEPS_FAILED=true
[ $DEPS_FAILED == false ] && opam install $PACKAGE
echo ::endgroup::
[ $DEPS_FAILED == false ] || echo Dependencies broken
done

@fpottier
Copy link
Collaborator Author

fpottier commented Sep 9, 2024

I think that's part of the CI

Thanks, I didn't know.

@liyishuai
Copy link
Member

Given that all downstream dependants still compile, propose merging if no other concerns arise by Fri 13 Sep AoE.

Copy link
Member

@pmetzger pmetzger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we should improve the test suite, fwiw.

@liyishuai
Copy link
Member

I do think we should improve the test suite, fwiw.

@liyishuai liyishuai merged commit 40600e3 into ocaml-community:master Sep 14, 2024
73 checks passed
@fpottier fpottier deleted the refactoring branch September 14, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants