A compound of formula I ': or a pharmaceutically acceptable salt thereof, wherein: Ring A is wherein Ring A is optionally substituted with 1-4 groups selected from fluorine, -CN, -OR, or C 1-6 aliphatic optionally substituted with 1-3 fluorine atoms; Ring B is a 5-6 membered heteroaryl ring having 1-3 heteroatoms independently selected from nitrogen, oxygen, or sulfur; R 1 is hydrogen, -Cy, or C 1-6 aliphatic optionally substituted with -Cy and optionally further substituted with 1-4 groups selected from fluorine, -CN, or -OR; each -Cy is independently a 6-membered aryl ring containing 0-2 nitrogen atoms, or a 4-7 membered saturated monocyclic ring having 0-2 heteroatoms independently selected from nitrogen, oxygen, or sulphur, wherein -Cy is optionally substituted with 1-4 groups selected from fluorine, -CN, or -OR; R 2 is hydrogen, -CN, -OR, -Cy, or C 1-10 aliphatic optionally substituted with -Cy and optionally further substituted with 1-5 groups selected from fluorine, -CN, or -OR; or: two R 2 groups on the same carbon are optionally taken together to form =O; n is 1, 2, or 3; X 1 is N or C(R 3); R 3 is -R, halogen, or -OR; each R is independently hydrogen or C 1-6 aliphatic optionally substituted with 1-3 fluorine atoms; L is selected from a covalent bond or a C 1-6 membered straight or branched, saturated or unsaturated hydrocarbon chain wherein one methylene unit of L is optionally replaced by-S 2 - or -C N(R y)-, wherein R y is R or -CH 2 phenyl; and R 4 is halogen, R, phenyl, or a 5-6-membered heteroaryl ring having 1-3 heteroatoms independently selected from nitrogen, oxygen, or sulphur, wherein R 4 is optionally substituted with 1-4 groups independently selected from halogen, -CN, -OR, -C OH, or C 1-6 aliphatic optionally substituted with 1-3 fluorine atoms. Ring A is wherein Ring A is optionally substituted with 1-4 groups selected from fluorine, -CN, -OR, or C 1-6 aliphatic optionally substituted with 1-3 fluorine atoms; Ring B is a 5-6 membered heteroaryl ring having 1-3 heteroatoms independently selected from nitrogen, oxygen, or sulfur; R 1 is hydrogen, -Cy, or C 1-6 aliphatic optionally substituted with -Cy and optionally further substituted with 1-4 groups selected from fluorine, -CN, or -OR; each -Cy is independently a 6-membered aryl ring containing 0-2 nitrogen atoms, or a 4-7 membered saturated monocyclic ring having 0-2 heteroatoms independently selected from nitrogen, oxygen, or sulphur, wherein -Cy is optionally substituted with 1-4 groups selected from fluorine, -CN, or -OR; R 2 is hydrogen, -CN, -OR, -Cy, or C 1-10 aliphatic optionally substituted with -Cy and optionally further substituted with 1-5 groups selected from fluorine, -CN, or -OR; or: two R 2 groups on the same carbon are optionally taken together to form =O; n is 1, 2, or 3; X 1 is N or C(R 3); R 3 is -R, halogen, or -OR; each R is independently hydrogen or C 1-6 aliphatic optionally substituted with 1-3 fluorine atoms; L is selected from a covalent bond or a C 1-6 membered straight or branched, saturated or unsaturated hydrocarbon chain wherein one methylene unit of L is optionally replaced by-S 2 - or -C N(R y)-, wherein R y is R or -CH 2 phenyl; and R 4 is halogen, R, phenyl, or a 5-6-membered heteroaryl ring having 1-3 heteroatoms independently selected from nitrogen, oxygen, or sulphur, wherein R 4 is optionally substituted with 1-4 groups independently selected from halogen, -CN, -OR, -C OH, or C 1-6 aliphatic optionally substituted with 1-3 fluorine atoms.