|
| 1 | +Issue: USE-PACKAGE-SHADOWING-CONFLICTS |
| 2 | +Forum: Cleanup |
| 3 | +Category: CLARIFICATION CHANGE |
| 4 | +References: USE-PACKAGE `shadowing symbols list' |
| 5 | +Edit History: 02-May-25, Version 1 by Umut Tuna Akgül |
| 6 | + |
| 7 | +Problem description: |
| 8 | + |
| 9 | + The description of the function USE-PACKAGE states that "USE-PACKAGE |
| 10 | + checks for name conflicts between the newly imported symbols and |
| 11 | + those already accessible in package", while the glossary entry for |
| 12 | + `shadowing symbols list' states that `shadowing symbols' are those |
| 13 | + "that are to be exempted from `symbol conflict errors' detected when |
| 14 | + packages are used". |
| 15 | + |
| 16 | +Proposal (USE-PACKAGE-SHADOWING-CONFLICTS:IGNORE-SHADOWING-CONFLICTS): |
| 17 | + |
| 18 | + This proposal amends the description of USE-PACKAGE such that |
| 19 | + "USE-PACKAGE checks for name conflicts between the newly imported |
| 20 | + symbols and those already accessible in package" is followed by: |
| 21 | + |
| 22 | + "unless when the accessible symbol is a shadowing symbol in package" |
| 23 | + |
| 24 | +Test Cases: |
| 25 | + |
| 26 | + (defpackage foo (:shadow quux)) |
| 27 | + (defpackage bar (:export quux)) |
| 28 | + (use-package 'bar 'foo) => T |
| 29 | + |
| 30 | + (defpackage baz (:export foobar)) |
| 31 | + (intern "FOOBAR" 'foo) |
| 32 | + (use-package 'baz 'foo) => ERROR |
| 33 | + |
| 34 | +Rationale: |
| 35 | + |
| 36 | + The current description of USE-PACKAGE is in conflict with the |
| 37 | + description of a shadowing symbol. If the description of |
| 38 | + USE-PACKAGE is the correct one, then the definition of the term |
| 39 | + `shadowing symbol' is invalid, and PACKAGE-SHADOWING-SYMBOLS ceases |
| 40 | + to be meaningful. |
| 41 | + |
| 42 | +Current practice: |
| 43 | + |
| 44 | + ECL 24.5.10 |
| 45 | + Armed Bear Common Lisp 1.9.3 |
| 46 | + SBCL 2.4.5 |
| 47 | + (use-package 'bar 'foo) => T |
| 48 | + (use-package 'baz 'foo) => ERROR |
| 49 | + |
| 50 | +Cost to Implementors: |
| 51 | + |
| 52 | + Small. If any implementation only checks that a symbol is |
| 53 | + accessible, it would only need to add a second check that the symbol |
| 54 | + is not in PACKAGE-SHADOWING-SYMBOLS. |
| 55 | + |
| 56 | +Cost to Users: |
| 57 | + |
| 58 | + Very small. Code written with the expectation that the shadowing |
| 59 | + status of a symbol does not persist across various USE-PACKAGE and |
| 60 | + UNUSE-PACKAGE operations will need to be rewritten. |
| 61 | + |
| 62 | +Cost of non-adoption: |
| 63 | + |
| 64 | + Due to order of options in DEFPACKAGE, a package in :USE which |
| 65 | + conflicts with a symbol in :SHADOW or :SHADOWING-IMPORT-FROM would |
| 66 | + signal an error, which would run counter to user intent. |
| 67 | + |
| 68 | +Performance impact: |
| 69 | + |
| 70 | + In the worst case scenario, this will add N*M comparisons to |
| 71 | + USE-PACKAGE, where N is the number of external symbols in the used |
| 72 | + package and M is the number of shadowing symbols in the using |
| 73 | + package. More likely N will be the number of external conflicting |
| 74 | + symbols, and if the shadowing status of a symbol is stored M can be |
| 75 | + omitted. Ultimately, the performance is unlikely to be significant |
| 76 | + or noticable. |
| 77 | + |
| 78 | +This will add a check to USE-PACKAGE for every conflicting symbol. |
| 79 | + This check, depending on the implementation, may be a single |
| 80 | + operation or, in the worst case scenario, a comparison against all |
| 81 | + shadowing symbols. Regardless, the impact is likely to be |
| 82 | + ultimately minimal. |
| 83 | + |
| 84 | +Benefits: |
| 85 | + |
| 86 | + Users would avoid correctable errors during DEFPACKAGE where a |
| 87 | + package in :USE conflicts with a symbol in :SHADOW or |
| 88 | + :SHADOWING-IMPORT-FROM, which goes against user intent. |
| 89 | + |
| 90 | +Esthetics: |
| 91 | + |
| 92 | + None. |
| 93 | + |
| 94 | +Discussion: |
| 95 | + |
| 96 | + None. |
| 97 | + |
0 commit comments